import { MigrationInterface, QueryRunner, Table, TableIndex } from "typeorm";

export class CreateTallerClientes1739952000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.createTable(
      new Table({
        name: "taller_clientes",
        columns: [
          { name: "tarjeta", type: "varchar", length: "24", isPrimary: true },
          { name: "nombre", type: "varchar", length: "255" },
          { name: "direccion", type: "varchar", length: "255" },
          { name: "telefono", type: "varchar", length: "48", isNullable: true },
          { name: "celular", type: "varchar", length: "10", isNullable: true },
          { name: "nit", type: "varchar", length: "24" },
          { name: "email", type: "varchar", length: "255", isNullable: true },
          {
            name: "created_at",
            type: "timestamp",
            default: "CURRENT_TIMESTAMP",
          },
          {
            name: "updated_at",
            type: "timestamp",
            default: "CURRENT_TIMESTAMP",
            onUpdate: "CURRENT_TIMESTAMP",
          },
        ],
      }),
      true,
    );

    await queryRunner.createIndex(
      "taller_clientes",
      new TableIndex({
        name: "IDX_taller_clientes_nombre",
        columnNames: ["nombre"],
      }),
    );

    await queryRunner.createIndex(
      "taller_clientes",
      new TableIndex({
        name: "IDX_taller_clientes_nit",
        columnNames: ["nit"],
      }),
    );

    await queryRunner.createIndex(
      "taller_clientes",
      new TableIndex({
        name: "IDX_taller_clientes_tarjeta",
        columnNames: ["tarjeta"],
      }),
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.dropTable("taller_clientes", true);
  }
}
