import { MigrationInterface, QueryRunner } from 'typeorm';

export class addEnumBaseAsset1701587112779 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
        INSERT INTO public.assets (id, workspace_id, parent_ids, project_id, name, title, icon, scope_id, is_abstract, created_at, updated_at, deleted_at, creator_user_id) VALUES ('00000000-0000-0000-0000-000000000020', '00000000-0000-0000-0000-000000000001', '{}', 1, null, '[[t:Structure]]', 'box-1-fill', 3, true, '2023-12-03 18:45:14.649425 +00:00', '2023-12-03 19:12:03.793151 +00:00', null, null);
        INSERT INTO public.asset_blocks (project_id, block_key, asset_id, title, props, created_at, updated_at, index, has_formula) VALUES (1, 1, '00000000-0000-0000-0000-000000000020', '[[t:Info]]', '{"\\\\fields": null, "index\\\\fields": 1, "title\\\\fields": "[[t:Fields]]", "field\\\\fields\\\\type": "struct", "field\\\\fields\\\\multiple": true, "field\\\\fields\\\\params\\\\type": {"assetId": "00000000-0000-0000-0000-000000000021"}}', '2023-12-03 18:45:48.740084 +00:00', '2023-12-03 19:12:03.793151 +00:00', 1, false);
    `);
    await queryRunner.query(`
        INSERT INTO public.assets (id, workspace_id, parent_ids, project_id, name, title, icon, scope_id, is_abstract, created_at, updated_at, deleted_at, creator_user_id) VALUES ('00000000-0000-0000-0000-000000000021', '00000000-0000-0000-0000-000000000001', '{00000000-0000-0000-0000-000000000020}', 1, null, '[[t:StructureField]]', null, 3, false, '2023-12-03 18:51:19.372203 +00:00', '2023-12-03 19:32:52.452284 +00:00', null, null);
        INSERT INTO public.asset_blocks (project_id, block_key, asset_id, title, props, created_at, updated_at, index, has_formula) VALUES (1, 1, '00000000-0000-0000-0000-000000000021', null, '{"\\\\fields": [0, 1, 2, 3], "\\\\fields\\\\0\\\\name": "name", "\\\\fields\\\\0\\\\type": "string", "\\\\fields\\\\1\\\\name": "title", "\\\\fields\\\\1\\\\type": "string", "\\\\fields\\\\2\\\\name": "type", "\\\\fields\\\\2\\\\type": "attributeType", "\\\\fields\\\\3\\\\name": "multiple", "\\\\fields\\\\3\\\\type": "checkbox", "\\\\fields\\\\0\\\\title": "[[t:StructureFieldName]]", "\\\\fields\\\\1\\\\title": "[[t:StructureFieldTitle]]", "\\\\fields\\\\2\\\\title": "[[t:StructureFieldType]]", "\\\\fields\\\\3\\\\title": "[[t:StructureFieldMultiple]]", "\\\\fields\\\\0\\\\multiple": false, "\\\\fields\\\\1\\\\multiple": false, "\\\\fields\\\\2\\\\multiple": false, "\\\\fields\\\\3\\\\multiple": false}', '2023-12-03 19:32:52.452284 +00:00', '2023-12-03 19:32:52.452284 +00:00', null, false);
    `);
    await queryRunner.query(`
        INSERT INTO public.assets (id, workspace_id, parent_ids, project_id, name, title, icon, scope_id, is_abstract, created_at, updated_at, deleted_at, creator_user_id) VALUES ('00000000-0000-0000-0000-000000000022', '00000000-0000-0000-0000-000000000001', '{00000000-0000-0000-0000-000000000020}', 1, null, '[[t:EnumItem]]', null, 3, false, '2023-12-03 19:42:06.175254 +00:00', '2023-12-03 22:44:32.491007 +00:00', null, null);
        INSERT INTO public.asset_blocks (project_id, block_key, asset_id, title, props, created_at, updated_at, index, has_formula) VALUES (1, 1, '00000000-0000-0000-0000-000000000022', null, '{"\\\\fields": [0, 1], "\\\\fields\\\\0": null, "\\\\fields\\\\1": null, "\\\\fields\\\\0\\\\name": "name", "\\\\fields\\\\0\\\\type": "string", "\\\\fields\\\\1\\\\name": "title", "\\\\fields\\\\1\\\\type": "string", "\\\\fields\\\\0\\\\title": "[[t:EnumItemName]]", "\\\\fields\\\\1\\\\title": "[[t:EnumItemTitle]]"}', '2023-12-03 21:45:25.513112 +00:00', '2023-12-03 22:44:32.491007 +00:00', null, false);
    `);
    await queryRunner.query(`
        INSERT INTO public.assets (id, workspace_id, parent_ids, project_id, name, title, icon, scope_id, is_abstract, created_at, updated_at, deleted_at, creator_user_id) VALUES ('00000000-0000-0000-0000-000000000023', '00000000-0000-0000-0000-000000000001', '{}', 1, null, '[[t:Enum]]', 'stack-fill', 3, true, '2023-12-03 19:41:47.077038 +00:00', '2023-12-03 23:32:09.501950 +00:00', null, null);
        INSERT INTO public.asset_blocks (project_id, block_key, asset_id, title, props, created_at, updated_at, index, has_formula) VALUES (1, 1, '00000000-0000-0000-0000-000000000023', '[[t:Info]]', '{"\\\\items": null, "untitled1": null, "index\\\\items": 1, "title\\\\items": "[[t:Items]]", "field\\\\items\\\\type": "struct", "field\\\\items\\\\multiple": true, "field\\\\items\\\\params\\\\type": {"assetId": "00000000-0000-0000-0000-000000000022"}}', '2023-12-03 22:44:50.452839 +00:00', '2023-12-03 22:48:37.892137 +00:00', 1, false);
    `);

    await queryRunner.query(`
        INSERT INTO asset_comps(project_id, id)
        SELECT project_id, id
        FROM assets
        ON CONFLICT DO NOTHING;
        INSERT INTO asset_block_comps(project_id, asset_id, block_key)
        SELECT project_id, asset_id, block_key
        FROM asset_blocks
        ON CONFLICT DO NOTHING;
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
        DELETE FROM public.assets 
        WHERE id = '00000000-0000-0000-0000-000000000020'
    `);
    await queryRunner.query(`
        DELETE FROM public.assets 
        WHERE id = '00000000-0000-0000-0000-000000000021'
    `);
    await queryRunner.query(`
        DELETE FROM public.assets 
        WHERE id = '00000000-0000-0000-0000-000000000022'
    `);
    await queryRunner.query(`
        DELETE FROM public.assets 
        WHERE id = '00000000-0000-0000-0000-000000000023'
    `);
  }
}
