import { MigrationInterface, QueryRunner } from 'typeorm';

export class addInsuranceInqueryTable1697153353412
  implements MigrationInterface
{
  name = 'addInsuranceInqueryTable1697153353412';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`ALTER TABLE \`driving_offenses\` 
CHANGE COLUMN \`client\` \`client\` ENUM('site', 'app', 'panel') NOT NULL DEFAULT 'site' ;`);

    await queryRunner.query(`ALTER TABLE \`negative_scores\` 
CHANGE COLUMN \`client\` \`client\` ENUM('site', 'app', 'panel') NOT NULL DEFAULT 'site' ;`);

    await queryRunner.query(`CREATE TABLE IF NOT EXISTS \`insurance_third_party_inquires\` (
  \`id\` INT(11) NOT NULL AUTO_INCREMENT,
  \`userId\` CHAR(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  \`carId\` INT(11) NOT NULL,
  \`plateNumber\` VARCHAR(128) NOT NULL,
  \`nationalCode\` VARCHAR(45) NOT NULL,
  \`companyName\` VARCHAR(45) NOT NULL,
  \`companyCode\` INT(11) NOT NULL,
  \`startedAt\` DATE NOT NULL,
  \`expiredAt\` DATE NOT NULL,
  \`newInsurancePeriod\` VARCHAR(45) NULL DEFAULT NULL,
  \`riskFactor\` INT(11) NULL DEFAULT NULL,
  \`hasDamage\` TINYINT(1) NOT NULL DEFAULT 0,
  \`previousDiscount\` INT(11) NULL DEFAULT NULL,
  \`driverDiscount\` INT(11) NULL DEFAULT NULL,
  \`lifeDamageCount\` INT(11) NOT NULL DEFAULT 0,
  \`financialDamageCount\` INT(11) NOT NULL DEFAULT 0,
  \`driverDamageCount\` INT(11) NOT NULL DEFAULT 0,
  \`carMakerName\` VARCHAR(45) NULL DEFAULT NULL,
  \`carMakerCode\` INT(11) NULL DEFAULT NULL,
  \`carGroup\` VARCHAR(45) NULL DEFAULT NULL,
  \`vehicleCode\` INT(11) NULL DEFAULT NULL,
  \`carModelName\` VARCHAR(45) NULL DEFAULT NULL,
  \`carMakeYear\` VARCHAR(45) NULL DEFAULT NULL,
  \`client\` ENUM('site', 'app', 'panel', 'system') NOT NULL DEFAULT 'site',
  \`createdAt\` DATETIME NOT NULL,
  \`updatedAt\` DATETIME NOT NULL,
  PRIMARY KEY (\`id\`),
  INDEX \`fk_insurance_inquires_users1_idx\` (\`userId\` ASC),
  INDEX \`fk_insurance_inquires_cars1_idx\` (\`carId\` ASC),
  CONSTRAINT \`fk_insurance_inquires_users1\`
    FOREIGN KEY (\`userId\`)
    REFERENCES \`users\` (\`id\`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT \`fk_insurance_inquires_cars1\`
    FOREIGN KEY (\`carId\`)
    REFERENCES \`cars\` (\`id\`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    //
  }
}
