-- CreateEnum
CREATE TYPE "CommercialType" AS ENUM ('CORP', 'PERS');

-- CreateTable
CREATE TABLE "CustomerBranchCitizen" (
    "id" TEXT NOT NULL,
    "namePrefix" TEXT,
    "firstName" TEXT NOT NULL,
    "firstNameEN" TEXT,
    "middleName" TEXT,
    "middleNameEN" TEXT,
    "lastName" TEXT NOT NULL,
    "lastNameEN" TEXT,
    "issueDate" DATE NOT NULL,
    "expireDate" DATE NOT NULL,
    "nationality" TEXT NOT NULL,
    "religion" TEXT NOT NULL,
    "gender" TEXT NOT NULL,
    "address" TEXT,
    "addressEN" TEXT,
    "soi" TEXT,
    "soiEN" TEXT,
    "moo" TEXT,
    "mooEN" TEXT,
    "street" TEXT,
    "streetEN" TEXT,
    "provinceId" TEXT,
    "districtId" TEXT,
    "subDistrictId" TEXT,

    CONSTRAINT "CustomerBranchCitizen_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CustomerBranchPoa" (
    "id" TEXT NOT NULL,

    CONSTRAINT "CustomerBranchPoa_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CustomerBranchHouseRegis" (
    "id" TEXT NOT NULL,
    "registrationOffice" TEXT NOT NULL,
    "houseId" TEXT NOT NULL,
    "houseNo" TEXT NOT NULL,
    "villageNo" TEXT NOT NULL,
    "address" TEXT,
    "addressEN" TEXT,
    "soi" TEXT,
    "soiEN" TEXT,
    "moo" TEXT,
    "mooEN" TEXT,
    "street" TEXT,
    "streetEN" TEXT,
    "provinceId" TEXT,
    "districtId" TEXT,
    "subDistrictId" TEXT,
    "namePrefix" TEXT,
    "firstName" TEXT NOT NULL,
    "firstNameEN" TEXT,
    "middleName" TEXT,
    "middleNameEN" TEXT,
    "lastName" TEXT NOT NULL,
    "lastNameEN" TEXT,
    "issueDate" DATE NOT NULL,
    "expireDate" DATE NOT NULL,
    "nationality" TEXT NOT NULL,
    "religion" TEXT NOT NULL,
    "gender" TEXT NOT NULL,
    "marriageStatus" TEXT NOT NULL,
    "citizenId" TEXT NOT NULL,
    "birthDate" DATE NOT NULL,
    "motherFullName" TEXT NOT NULL,
    "motherFullNameEN" TEXT,
    "motherCitizenId" TEXT NOT NULL,
    "motherNationality" TEXT,
    "fatherFullName" TEXT NOT NULL,
    "fatherFullNameEN" TEXT,
    "fatherCitizenId" TEXT NOT NULL,
    "fatherNationality" TEXT,

    CONSTRAINT "CustomerBranchHouseRegis_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CustomerBranchCommercialRegis" (
    "id" TEXT NOT NULL,
    "registrationNo" TEXT NOT NULL,
    "registrationType" "CommercialType" NOT NULL,
    "requestNo" TEXT,
    "namePrefix" TEXT,
    "fullName" TEXT NOT NULL,
    "fullNameEN" TEXT NOT NULL,
    "registrationDate" TEXT NOT NULL,
    "romanLetter" TEXT,

    CONSTRAINT "CustomerBranchCommercialRegis_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CustomerBranchVatRegis" (
    "id" TEXT NOT NULL,

    CONSTRAINT "CustomerBranchVatRegis_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "CustomerBranchCitizen" ADD CONSTRAINT "CustomerBranchCitizen_provinceId_fkey" FOREIGN KEY ("provinceId") REFERENCES "Province"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CustomerBranchCitizen" ADD CONSTRAINT "CustomerBranchCitizen_districtId_fkey" FOREIGN KEY ("districtId") REFERENCES "District"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CustomerBranchCitizen" ADD CONSTRAINT "CustomerBranchCitizen_subDistrictId_fkey" FOREIGN KEY ("subDistrictId") REFERENCES "SubDistrict"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CustomerBranchHouseRegis" ADD CONSTRAINT "CustomerBranchHouseRegis_provinceId_fkey" FOREIGN KEY ("provinceId") REFERENCES "Province"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CustomerBranchHouseRegis" ADD CONSTRAINT "CustomerBranchHouseRegis_districtId_fkey" FOREIGN KEY ("districtId") REFERENCES "District"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CustomerBranchHouseRegis" ADD CONSTRAINT "CustomerBranchHouseRegis_subDistrictId_fkey" FOREIGN KEY ("subDistrictId") REFERENCES "SubDistrict"("id") ON DELETE SET NULL ON UPDATE CASCADE;
