/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class AddUserCalendar1740402538635 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      create table if not exists user_calendar (
        id integer generated by default as identity,
        account_id integer not null,
        user_id integer not null,
        time_buffer_before integer,
        time_buffer_after integer,
        appointment_limit integer,
        primary key (id),
        foreign key (account_id) references account(id) on delete cascade,
        foreign key (user_id) references users(id) on delete cascade
      );

      create index if not exists idx_account_user on user_calendar(account_id, user_id);

      create table if not exists user_calendar_interval (
        id integer generated by default as identity,
        account_id integer not null,
        calendar_id integer not null,
        day_of_week text not null,
        time_from time without time zone not null,
        time_to time without time zone not null,
        primary key (id),
        foreign key (account_id) references account(id) on delete cascade,
        foreign key (calendar_id) references user_calendar(id) on delete cascade
      );

      create index if not exists idx_account_calendar on user_calendar_interval(account_id, calendar_id);
    `);
  }

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