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

export class AddForms1717599382958 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      CREATE TABLE site_form (
        id integer GENERATED BY DEFAULT AS IDENTITY,
        account_id integer NOT NULL,
        name text NOT NULL,
        code text NOT NULL,
        is_active boolean NOT NULL,
        title text,
        type text NOT NULL,
        color_main text,
        color_background text,
        color_font text,
        consent_enabled boolean NOT NULL DEFAULT false,
        consent_text text,
        consent_url text,
        PRIMARY KEY (id),
        FOREIGN KEY (account_id) REFERENCES account(id) ON DELETE CASCADE,
        UNIQUE (code)
      );

      CREATE TABLE site_form_page (
        id integer GENERATED BY DEFAULT AS IDENTITY,
        account_id integer NOT NULL,
        form_id integer NOT NULL,
        title text,
        PRIMARY KEY (id),
        FOREIGN KEY (account_id) REFERENCES account(id) ON DELETE CASCADE,
        FOREIGN KEY (form_id) REFERENCES site_form(id) ON DELETE CASCADE
      );

      CREATE TABLE site_form_field (
        id integer GENERATED BY DEFAULT AS IDENTITY,
        account_id integer NOT NULL,
        page_id integer NOT NULL,
        title text NOT NULL,
        type text NOT NULL,
        is_required boolean NOT NULL DEFAULT false,
        PRIMARY KEY (id),
        FOREIGN KEY (account_id) REFERENCES account(id) ON DELETE CASCADE,
        FOREIGN KEY (page_id) REFERENCES site_form_page(id) ON DELETE CASCADE
      );        
    `);
  }

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