"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateContentTypesModule = void 0;
const collation_type_1 = require("./collation-type");
const common_1 = require("@nestjs/common");
const change_case_1 = require("change-case");
const fs = require("fs-extra");
const path = require("path");
const generateContentTypesModule = (contentTypesSchema) => {
    Object.keys(contentTypesSchema).forEach((contentTypeId) => {
        generateContentTypeModule(contentTypesSchema[contentTypeId], contentTypesSchema);
    });
};
exports.generateContentTypesModule = generateContentTypesModule;
const generateContentTypeModule = (contentType, contentTypesSchema) => {
    const rootFolder = process.env.INIT_CWD;
    try {
        fs.removeSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}`);
    }
    catch (err) {
        console.warn(err);
    }
    fs.mkdirSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto`, {
        recursive: true,
    });
    fs.mkdirSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/content-types`, {
        recursive: true,
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/${(0, change_case_1.paramCase)(contentType.collectionName)}.module.ts`, generateContentTypeModuleContent(contentType), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/${(0, change_case_1.paramCase)(contentType.collectionName)}.controller.ts`, generateContentTypeControllerContent(contentType), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.controller.ts`, generateContentTypeAdminControllerContent(contentType), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/${(0, change_case_1.paramCase)(contentType.collectionName)}.service.ts`, generateContentTypeServiceContent(contentType), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto/${(0, change_case_1.paramCase)(contentType.collectionName)}.dto.ts`, generateContentTypeDtoContent(contentType, contentTypesSchema), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto/admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.dto.ts`, generateContentTypeAdminDtoContent(contentType, contentTypesSchema), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto/create-${(0, change_case_1.paramCase)(contentType.collectionName)}.input.ts`, generateContentTypeCreateInputContent(contentType, contentTypesSchema), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto/create-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input.ts`, generateContentTypeCreateAdminInputContent(contentType, contentTypesSchema), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto/update-${(0, change_case_1.paramCase)(contentType.collectionName)}.input.ts`, generateContentTypeUpdateInputContent(contentType, contentTypesSchema), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto/update-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input.ts`, generateContentTypeUpdateAdminInputContent(contentType, contentTypesSchema), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/dto/index.ts`, generateContentTypeDtoIndexContent(contentType), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/index.ts`, generateContentTypeModuleIndexContent(contentType), {
        encoding: 'utf-8',
    });
    fs.writeFileSync(`${rootFolder}/src/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/content-types/schema.json`, JSON.stringify(contentType), {
        encoding: 'utf-8',
    });
};
const generateContentTypeModuleContent = (contentType) => {
    const template = `import { Module } from '@nestjs/common';
import { ${(0, change_case_1.pascalCase)(contentType.collectionName)}Service } from './${(0, change_case_1.paramCase)(contentType.collectionName)}.service';
import { Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Controller } from './admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.controller';
import { ${(0, change_case_1.pascalCase)(contentType.collectionName)}Controller } from './${(0, change_case_1.paramCase)(contentType.collectionName)}.controller';


@Module({
  controllers: [Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Controller,${(0, change_case_1.pascalCase)(contentType.collectionName)}Controller],
  providers: [${(0, change_case_1.pascalCase)(contentType.collectionName)}Service],
  exports: [${(0, change_case_1.pascalCase)(contentType.collectionName)}Service],
})
export class ${(0, change_case_1.pascalCase)(contentType.collectionName)}Module {}
`;
    return template;
};
const generateContentTypeControllerContent = (contentType) => {
    const template = `
import {
  Body,
  Controller,
  Delete,
  Get,
  HttpCode,
  HttpStatus,
  Param,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiBody,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { Prisma } from '@prisma/client';
import {
  OpenApiResponse,
  FindManyArgs,
  OpenApiPaginationResponse,
  FindOneArgs,
  SuccessResponseDto,
} from '@moonlightjs/common';
import { ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto } from './dto/${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';
import { ${(0, change_case_1.pascalCase)(contentType.collectionName)}Service } from './${(0, change_case_1.paramCase)(contentType.collectionName)}.service';
import { Update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input } from './dto/update-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
import { Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input } from './dto/create-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';

@ApiTags('${(0, change_case_1.paramCase)(contentType.collectionName)}')
@Controller({
  path: '${(0, change_case_1.paramCase)(contentType.collectionName)}',
  version: '1',
})
// @UseGuards(JwtAuthGuard)
export class ${(0, change_case_1.pascalCase)(contentType.collectionName)}Controller {
  constructor(protected readonly ${(0, change_case_1.camelCase)(contentType.collectionName)}Service: ${(0, change_case_1.pascalCase)(contentType.collectionName)}Service) {}

  @ApiBody({
    type: Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
  })
  @OpenApiResponse({
    status: HttpStatus.CREATED,
    model: ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto,
  })
  @Post()
  create(
    @Body() create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input: Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
    @Query() params: Omit<Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}CreateArgs, 'data'>,
  ) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.create({
      ...params,
      data: {
        ...create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input
      },
    });
  }

  @ApiQuery({
    type: FindManyArgs,
  })
  @OpenApiResponse({
    status: HttpStatus.OK,
    model: ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto,
    isArray: true,
  })
  @Get()
  findAll(@Query() params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindManyArgs) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.findAll(params);
  }

  @ApiQuery({
    type: FindManyArgs,
  })
  @OpenApiPaginationResponse(${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto)
  @Get('/pagination')
  findAllPagination(@Query() params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindManyArgs) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.findAllPagination(params);
  }

  @ApiQuery({
    type: FindOneArgs,
  })
  @OpenApiResponse({ status: HttpStatus.OK, model: ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto })
  @Get(':id')
  findOne(
    @Param('id') id: string,
    @Query() params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindUniqueArgs,
  ) {
    params.where = {
      id,
    };
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.findOne(params);
  }

  @OpenApiResponse({ status: HttpStatus.OK, model: ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto })
  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input: Update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
    @Query() params: Omit<Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}UpdateArgs, 'data' | 'where'>,
  ) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.update({
      ...params,
      where: {
        id,
      },
      data: {
        ...update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
      },
    });
  }

  @ApiResponse({ status: HttpStatus.OK, type: SuccessResponseDto })
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.remove({
      id,
    });
  }
}
`;
    return template;
};
const generateContentTypeAdminControllerContent = (contentType) => {
    const template = `
import {
  Body,
  Controller,
  Delete,
  Get,
  HttpCode,
  HttpStatus,
  Param,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiBody,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { Prisma } from '@prisma/client';
import {
  OpenApiResponse,
  FindManyArgs,
  OpenApiPaginationResponse,
  FindOneArgs,
  SuccessResponseDto,
} from '@moonlightjs/common';
import { ${(0, change_case_1.pascalCase)(contentType.collectionName)}Service } from './${(0, change_case_1.paramCase)(contentType.collectionName)}.service';
import { UpdateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input } from './dto/update-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
import { CreateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input } from './dto/create-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
import { Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto } from './dto/admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';

@ApiTags('admin-content-type-${(0, change_case_1.paramCase)(contentType.collectionName)}')
@Controller({
  path: 'admin/content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}',
  version: '1',
})
// @UseGuards(JwtAuthGuard)
export class Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Controller {
  constructor(protected readonly ${(0, change_case_1.camelCase)(contentType.collectionName)}Service: ${(0, change_case_1.pascalCase)(contentType.collectionName)}Service) {}

  @ApiBody({
    type: CreateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
  })
  @OpenApiResponse({
    status: HttpStatus.CREATED,
    model: Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto,
  })
  @Post()
  create(
    @Body() create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input: CreateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
    @Query() params: Omit<Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}CreateArgs, 'data'>,
  ) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.create({
      ...params,
      data: {
        ...create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input
      },
    }, Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto);
  }

  @ApiQuery({
    type: FindManyArgs,
  })
  @OpenApiResponse({
    status: HttpStatus.OK,
    model: Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto,
    isArray: true,
  })
  @Get()
  findAll(@Query() params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindManyArgs) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.findAll(params, Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto);
  }

  @ApiQuery({
    type: FindManyArgs,
  })
  @OpenApiPaginationResponse(Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto)
  @Get('/pagination')
  findAllPagination(@Query() params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindManyArgs) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.findAllPagination(params, Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto);
  }

  @ApiQuery({
    type: FindOneArgs,
  })
  @OpenApiResponse({ status: HttpStatus.OK, model: Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto })
  @Get(':id')
  findOne(
    @Param('id') id: string,
    @Query() params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindUniqueArgs,
  ) {
    params.where = {
      id,
    };
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.findOne(params, Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto);
  }

  ${contentType.options.draftAndPublish
        ? `@OpenApiResponse({ status: HttpStatus.OK, model: Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto })
@Patch(':id/published')
published(@Param('id') id: string) {
  return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.update(
    {
      where: {
        id,
      },
      data: {
        publishedAt: new Date(),
      },
    },
    Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto,
  );
}

@OpenApiResponse({ status: HttpStatus.OK, model: Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto })
@Patch(':id/un-published')
unPublished(@Param('id') id: string) {
  return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.update(
    {
      where: {
        id,
      },
      data: {
        publishedAt: null,
      },
    },
    Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto,
  );
}`
        : ''}
  @OpenApiResponse({ status: HttpStatus.OK, model: Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto })
  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input: UpdateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
    @Query() params: Omit<Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}UpdateArgs, 'data' | 'where'>,
  ) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.update({
      ...params,
      where: {
        id,
      },
      data: {
        ...update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input,
      },
    }, Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto);
  }

  @ApiResponse({ status: HttpStatus.OK, type: SuccessResponseDto })
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.${(0, change_case_1.camelCase)(contentType.collectionName)}Service.remove({
      id,
    });
  }
}
`;
    return template;
};
const generateContentTypeServiceContent = (contentType) => {
    const template = `
import { BadRequestException, Injectable } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import {
  PagedResultDto,
  Pagination,
  toDto,
  HttpErrorException,
} from '@moonlightjs/common';
import { PrismaService } from '@moonlightjs/common';
import { ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto } from './dto/${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';
import { Update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input } from './dto/update-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
import { Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input } from './dto/create-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';

const DEFAULT_SKIP = 0;
const DEFAULT_TAKE = 20;

@Injectable()
export class ${(0, change_case_1.pascalCase)(contentType.collectionName)}Service {
  constructor(
    protected prisma: PrismaService
  ) {}

  async findOne<TDto = any>(params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindFirstArgs, dtoType = ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto) : Promise<TDto> {
    const ${(0, change_case_1.camelCase)(contentType.collectionName)} = await this.prisma.${(0, change_case_1.camelCase)(contentType.collectionName)}.findFirst(params);
    return toDto<TDto>(dtoType, ${(0, change_case_1.camelCase)(contentType.collectionName)});
  }

  async findAll<TDto = any>(params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindManyArgs, dtoType = ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto): Promise<TDto[]> {
    params.skip = params.skip ?? DEFAULT_SKIP;
    params.take = params.take ?? DEFAULT_TAKE;
    const ${(0, change_case_1.camelCase)(contentType.collectionName)}s = await this.prisma.${(0, change_case_1.camelCase)(contentType.collectionName)}.findMany(params);
    return ${(0, change_case_1.camelCase)(contentType.collectionName)}s.map((${(0, change_case_1.camelCase)(contentType.collectionName)}) => toDto<TDto>(dtoType, ${(0, change_case_1.camelCase)(contentType.collectionName)}));
  }

  async findAllPagination<TDto = any>(
    params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}FindManyArgs, dtoType = ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto
  ): Promise<PagedResultDto<TDto>> {
    params.skip = params.skip ?? DEFAULT_SKIP;
    params.take = params.take ?? DEFAULT_TAKE;
    const [${(0, change_case_1.camelCase)(contentType.collectionName)}s, total] = await Promise.all([
      this.prisma.${(0, change_case_1.camelCase)(contentType.collectionName)}.findMany(params),
      this.prisma.${(0, change_case_1.camelCase)(contentType.collectionName)}.count({
        where: params.where,
      }),
    ]);
    return PagedResultDto.create({
      data: ${(0, change_case_1.camelCase)(contentType.collectionName)}s.map((${(0, change_case_1.camelCase)(contentType.collectionName)}) => toDto<TDto>(dtoType, ${(0, change_case_1.camelCase)(contentType.collectionName)})),
      pagination: Pagination.create({
        take: params.take,
        skip: params.skip,
        total: total,
      }),
    });
  }

  async create<TDto = any>(params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}CreateArgs, dtoType = ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto): Promise<TDto> {
    const ${(0, change_case_1.camelCase)(contentType.collectionName)} = await this.prisma.${(0, change_case_1.camelCase)(contentType.collectionName)}.create(params);
    return toDto<TDto>(dtoType, ${(0, change_case_1.camelCase)(contentType.collectionName)});
  }

  async update<TDto = any>(params: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}UpdateArgs, dtoType = ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto): Promise<TDto> {
    const ${(0, change_case_1.camelCase)(contentType.collectionName)} = await this.prisma.${(0, change_case_1.camelCase)(contentType.collectionName)}.update(params);
    return toDto<TDto>(dtoType, ${(0, change_case_1.camelCase)(contentType.collectionName)});
  }

  async remove(where: Prisma.${(0, change_case_1.pascalCase)(contentType.collectionName)}WhereUniqueInput): Promise<boolean> {
    const ${(0, change_case_1.camelCase)(contentType.collectionName)} = await this.prisma.${(0, change_case_1.camelCase)(contentType.collectionName)}.delete({
      where,
    });
    return !!${(0, change_case_1.camelCase)(contentType.collectionName)};
  }
}`;
    return template;
};
const generateContentTypeDtoContent = (contentType, contentTypesSchema) => {
    let attributeTxt = '';
    let enumImportTxt = '';
    let relationImportTxt = '';
    Object.keys(contentType.attributes).forEach((attributeName, index) => {
        const attribute = contentType.attributes[attributeName];
        if (attribute.private) {
            return;
        }
        if (attribute.type === 'enumeration') {
            enumImportTxt += `${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum,`;
        }
        let typeRelation = '';
        let arrayTxt = '';
        if (attribute.type === 'relation') {
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            typeRelation = `\n@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}Dto)`;
            arrayTxt = ['oneToMany', 'manyToMany'].includes(attrRelation.relation)
                ? 'isArray: true,'
                : '';
            relationImportTxt += `import { ${(0, change_case_1.pascalCase)(target.collectionName)}Dto } from '@content-type/${(0, change_case_1.paramCase)(target.collectionName)}/dto/${(0, change_case_1.paramCase)(target.collectionName)}.dto';`;
        }
        if (index !== 0)
            attributeTxt += '\n';
        const property = `
@ApiProperty({ type: ${generateOpenApiType(attribute, contentTypesSchema)},${attribute.required ? 'required: true, ' : 'required: false, '}${attribute.required ? 'nullable: true, ' : 'nullable: false, '}${attribute.type === 'enumeration'
            ? ` enum: ${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum,`
            : ''}${arrayTxt}})${typeRelation.length ? typeRelation : ''}
@Expose()
public readonly ${attributeName}: ${generateTypescriptType(attribute, attributeName, contentType.collectionName, contentTypesSchema)};
`;
        attributeTxt += property;
    });
    const template = `
import { ApiProperty } from '@nestjs/swagger';
import { Nullable } from '@moonlightjs/common';
import { Expose, Type } from 'class-transformer';${relationImportTxt.length ? `\n${relationImportTxt}` : ''}${enumImportTxt.length
        ? `\nimport { ${enumImportTxt} } from './admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';`
        : ''}
  

@Expose()
export class ${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto {
  @ApiProperty({ type: 'string', required: true })
  @Expose()
  public readonly id: string;
  ${attributeTxt}
  ${contentType.options.softDelete
        ? `\n  @ApiProperty({ type: 'string', required: true })
@Expose()
public readonly publishedAt: string;`
        : ''}
}
`;
    return template;
};
const generateContentTypeAdminDtoContent = (contentType, contentTypesSchema) => {
    let attributeTxt = '';
    let enumTxt = '';
    let relationImportTxt = '';
    Object.keys(contentType.attributes).forEach((attributeName, index) => {
        const attribute = contentType.attributes[attributeName];
        if (attribute.type === 'enumeration') {
            const attributeEnum = attribute;
            enumTxt += `
export enum ${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum {
  ${attributeEnum.enum
                .map((value) => {
                return `${(0, change_case_1.constantCase)(value)} = '${value}',`;
            })
                .join('\n')}
}`;
        }
        let typeRelation = '';
        let arrayTxt = '';
        if (attribute.type === 'relation') {
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            typeRelation = `\n@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}Dto)`;
            arrayTxt = ['oneToMany', 'manyToMany'].includes(attrRelation.relation)
                ? 'isArray: true,'
                : '';
            relationImportTxt += `import { ${(0, change_case_1.pascalCase)(target.collectionName)}Dto } from '@content-type/${(0, change_case_1.paramCase)(target.collectionName)}/dto/${(0, change_case_1.paramCase)(target.collectionName)}.dto';`;
        }
        if (index !== 0)
            attributeTxt += '\n';
        const property = `
@ApiProperty({ type: ${generateOpenApiType(attribute, contentTypesSchema)},${attribute.required ? 'required: true, ' : 'required: false, '}${attribute.required ? 'nullable: true, ' : 'nullable: false, '}${attribute.type === 'enumeration'
            ? ` enum: ${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum,`
            : ''}${arrayTxt}})${typeRelation.length ? typeRelation : ''}
@Expose()
public readonly ${attributeName}: ${generateTypescriptType(attribute, attributeName, contentType.collectionName, contentTypesSchema)};
`;
        attributeTxt += property;
    });
    const template = `
import { ApiProperty } from '@nestjs/swagger';
import { Nullable } from '@moonlightjs/common';
import { Expose, Type } from 'class-transformer';${relationImportTxt.length ? `\n${relationImportTxt}` : ''}

${enumTxt}

@Expose()
export class Admin${(0, change_case_1.pascalCase)(contentType.collectionName)}Dto {
  @ApiProperty({ type: 'string', required: true })
  @Expose()
  public readonly id: string;
  ${attributeTxt}
  ${contentType.options.draftAndPublish
        ? `\n  @ApiProperty({ type: 'string', required: true })
@Expose()
public readonly publishedAt: string;
@ApiProperty({ type: 'string', required: true, nullable: true })
@Expose()
public readonly publishedById: Nullable<string>;
@ApiProperty({ type: 'string', required: true, nullable: true })
@Expose()
public readonly publishedBy: Nullable<string>;`
        : ''}
  @ApiProperty({ type: 'string', required: true })
  @Expose()
  public readonly createdAt: string;
  @ApiProperty({ type: 'string', required: true, nullable: true })
  @Expose()
  public readonly createdById: Nullable<string>;
  @ApiProperty({ type: 'string', required: true, nullable: true })
  @Expose()
  public readonly createdBy: Nullable<string>;
  @ApiProperty({ type: 'string', required: true })
  @Expose()
  public readonly updatedAt: string;
  @ApiProperty({ type: 'string', required: true, nullable: true })
  @Expose()
  public readonly updatedById: Nullable<string>;
  @ApiProperty({ type: 'string', required: true, nullable: true })
  @Expose()
  public readonly updatedBy: Nullable<string>;${contentType.options.softDelete
        ? `\n  @ApiProperty({ type: 'string', required: true })
@Expose()
public readonly deletedAt: string;
@ApiProperty({ type: 'string', required: true, nullable: true })
@Expose()
public readonly deletedById: Nullable<string>;
@ApiProperty({ type: 'string', required: true, nullable: true })
@Expose()
public readonly deletedBy: Nullable<string>;`
        : ''}
}
`;
    return template;
};
const generateContentTypeCreateInputContent = (contentType, contentTypesSchema) => {
    let attributeTxt = '';
    let enumImportTxt = '';
    let relationTypeImportTxt = '';
    Object.keys(contentType.attributes).forEach((attributeName, index) => {
        const attribute = contentType.attributes[attributeName];
        if (attribute.type === 'enumeration') {
            enumImportTxt += `${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum,`;
        }
        if (index !== 0)
            attributeTxt += '\n';
        let property;
        if (attribute.type !== 'relation') {
            property = `
@ApiProperty({ type: ${generateOpenApiType(attribute, contentTypesSchema, false)},${attribute.required ? 'required: true, ' : 'required: false, '}${attribute.required ? 'nullable: true, ' : 'nullable: false, '}${attribute.type === 'enumeration'
                ? ` enum: ${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum`
                : ''}})
${generateValidateType(attribute, attributeName, contentType.collectionName)}
${attribute.required ? '' : '@IsOptional()'}
@Expose()
public readonly ${attributeName}: ${generateTypescriptType(attribute, attributeName, contentType.collectionName, contentTypesSchema, false)};
`;
        }
        else {
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            relationTypeImportTxt += `${(0, change_case_1.pascalCase)(target.collectionName)}CreateNested, `;
            property = `@ApiProperty({ required: true })
@ValidateNested()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}CreateNested)
public readonly ${attributeName}: ${(0, change_case_1.pascalCase)(target.collectionName)}CreateNested;`;
        }
        attributeTxt += property;
    });
    const template = `
import { ApiProperty } from '@nestjs/swagger';
import { IsDateStringISO, Nullable } from '@moonlightjs/common';
import { Expose, Type } from 'class-transformer';
import {
  IsBoolean,
  IsEnum,
  IsInt,
  IsObject,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  IsUUID,
  Matches,
  Max,
  MaxLength,
  Min,
  MinLength,
  ValidateNested
} from 'class-validator';
${enumImportTxt.length
        ? `\nimport { ${enumImportTxt} } from './admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';`
        : ''}${relationTypeImportTxt.length
        ? `import { ${relationTypeImportTxt} } from './create-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';`
        : ''}
@Expose()
export class Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input {
  ${attributeTxt}
}`;
    return template;
};
const generateContentTypeCreateAdminInputContent = (contentType, contentTypesSchema) => {
    let attributeTxt = '';
    let enumImportTxt = '';
    let relationTypeTxt = '';
    Object.keys(contentType.attributes).forEach((attributeName, index) => {
        const attribute = contentType.attributes[attributeName];
        if (attribute.type === 'enumeration') {
            enumImportTxt += `${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum,`;
        }
        if (index !== 0)
            attributeTxt += '\n';
        let property;
        if (attribute.type !== 'relation') {
            property = `
@ApiProperty({ type: ${generateOpenApiType(attribute, contentTypesSchema, false)},${attribute.required ? 'required: true, ' : 'required: false, '}${attribute.required ? 'nullable: true, ' : 'nullable: false, '}${attribute.type === 'enumeration'
                ? ` enum: ${(0, change_case_1.pascalCase)(contentType.collectionName)}${(0, change_case_1.pascalCase)(attributeName)}Enum`
                : ''}})
${generateValidateType(attribute, attributeName, contentType.collectionName)}
${attribute.required ? '' : '@IsOptional()'}
@Expose()
public readonly ${attributeName}: ${generateTypescriptType(attribute, attributeName, contentType.collectionName, contentTypesSchema, false)};
`;
        }
        else {
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            relationTypeTxt += `export class ${(0, change_case_1.pascalCase)(target.collectionName)}Id {
@ApiProperty({ required: true })
@IsUUID()
@IsNotEmpty()
public readonly id: string;
}

export class ${(0, change_case_1.pascalCase)(target.collectionName)}CreateNested {
@ApiProperty({ required: true })
@ValidateNested()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}Id)
public readonly connect: ${(0, change_case_1.pascalCase)(target.collectionName)}Id${['manyToMany', 'oneToMany'].includes(attrRelation.relation) ? '[]' : ''};
}\n`;
            property = `@ApiProperty({ required: true })
@ValidateNested()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}CreateNested)
public readonly ${attributeName}: ${(0, change_case_1.pascalCase)(target.collectionName)}CreateNested;`;
        }
        attributeTxt += property;
    });
    const template = `
import { ApiProperty } from '@nestjs/swagger';
import { IsDateStringISO, Nullable } from '@moonlightjs/common';
import { Expose, Type } from 'class-transformer';
import {
  IsBoolean,
  IsEnum,
  IsInt,
  IsObject,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  IsUUID,
  Matches,
  Max,
  MaxLength,
  Min,
  MinLength,
  ValidateNested
} from 'class-validator';
${enumImportTxt.length
        ? `\nimport { ${enumImportTxt} } from './admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';`
        : ''}

${relationTypeTxt}
@Expose()
export class CreateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input {
  ${attributeTxt}
}`;
    return template;
};
const generateContentTypeUpdateInputContent = (contentType, contentTypesSchema) => {
    let manyToManyRelationAttr = '';
    let relationAttrImportTxt = '';
    let omitPropertyTxt = '';
    Object.keys(contentType.attributes).forEach((attributeName, index) => {
        if (index !== 0)
            manyToManyRelationAttr += '\n';
        const attribute = contentType.attributes[attributeName];
        if (attribute.type === 'relation') {
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            if (['manyToMany', 'oneToMany'].includes(attrRelation.relation)) {
                manyToManyRelationAttr += `@ApiProperty({ required: ${attribute.required ? 'true' : 'false'} })
@ValidateNested()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}UpdateNested)
@Expose()
public readonly ${(0, change_case_1.pascalCase)(attributeName)}: ${(0, change_case_1.pascalCase)(target.collectionName)}UpdateNested;\n`;
                relationAttrImportTxt += `${(0, change_case_1.pascalCase)(target.collectionName)}UpdateNested,`;
                omitPropertyTxt += `'${attributeName}',`;
            }
        }
    });
    const template = `
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger';
import { Type, Expose } from 'class-transformer';
import { IsArray, IsOptional, ValidateNested } from 'class-validator';
import { Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input } from './create-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
${relationAttrImportTxt.length
        ? `import { ${relationAttrImportTxt} } from './update-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';`
        : ''}

export class Update${(0, change_case_1.pascalCase)(contentType.collectionName)}Input extends PartialType(${omitPropertyTxt.length
        ? `OmitType(Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input, [${omitPropertyTxt}])`
        : `Create${(0, change_case_1.pascalCase)(contentType.collectionName)}Input`}) {

    ${manyToManyRelationAttr}
}
`;
    return template;
};
const generateContentTypeUpdateAdminInputContent = (contentType, contentTypesSchema) => {
    let manyToManyRelationAttr = '';
    let relationAttrTxt = '';
    let targetIdTxt = '';
    let omitPropertyTxt = '';
    Object.keys(contentType.attributes).forEach((attributeName, index) => {
        if (index !== 0)
            manyToManyRelationAttr += '\n';
        const attribute = contentType.attributes[attributeName];
        if (attribute.type === 'relation') {
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            if (['manyToMany', 'oneToMany'].includes(attrRelation.relation)) {
                manyToManyRelationAttr += `@ApiProperty({ required: ${attribute.required ? 'true' : 'false'} })
@ValidateNested()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}UpdateNested)
@Expose()
public readonly ${(0, change_case_1.pascalCase)(attributeName)}: ${(0, change_case_1.pascalCase)(target.collectionName)}UpdateNested;\n`;
                relationAttrTxt += `
        export class ${(0, change_case_1.pascalCase)(target.collectionName)}UpdateNested {
@ApiProperty({ required: false, isArray: true, type: ${(0, change_case_1.pascalCase)(target.collectionName)}Id })
@ValidateNested({ each: true })
@IsArray()
@IsOptional()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}Id)
set?: ${(0, change_case_1.pascalCase)(target.collectionName)}Id[];
@ApiProperty({ required: false, isArray: true, type: ${(0, change_case_1.pascalCase)(target.collectionName)}Id })
@ValidateNested({ each: true })
@IsArray()
@IsOptional()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}Id)
disconnect?: ${(0, change_case_1.pascalCase)(target.collectionName)}Id[];
@ApiProperty({ required: false, isArray: true, type: ${(0, change_case_1.pascalCase)(target.collectionName)}Id })
@ValidateNested({ each: true })
@IsArray()
@IsOptional()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}Id)
delete?: ${(0, change_case_1.pascalCase)(target.collectionName)}Id[];
@ApiProperty({ required: false, isArray: true, type: ${(0, change_case_1.pascalCase)(target.collectionName)}Id })
@ValidateNested({ each: true })
@IsArray()
@IsOptional()
@Type(() => ${(0, change_case_1.pascalCase)(target.collectionName)}Id)
connect?:${(0, change_case_1.pascalCase)(target.collectionName)}Id[];
        }`;
                targetIdTxt += `${(0, change_case_1.pascalCase)(target.collectionName)}Id,`;
                omitPropertyTxt += `'${attributeName}',`;
            }
        }
    });
    const template = `
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger';
import { Type, Expose } from 'class-transformer';
import { IsArray, IsOptional, ValidateNested } from 'class-validator';
import { CreateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input, ${targetIdTxt} } from './create-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';

${relationAttrTxt}

export class UpdateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input extends PartialType(${omitPropertyTxt.length
        ? `OmitType(CreateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input, [${omitPropertyTxt}])`
        : `CreateAdmin${(0, change_case_1.pascalCase)(contentType.collectionName)}Input`}) {

    ${manyToManyRelationAttr}
}
`;
    return template;
};
const generateTypescriptType = (attribute, attributeName, modelName, contentTypesSchema, isDto = true) => {
    let type = '';
    switch (attribute.type) {
        case 'string':
        case 'password':
        case 'text':
        case 'richtext':
            type = 'string';
            break;
        case 'integer':
        case 'bigint':
        case 'float':
        case 'decimal':
            type = 'number';
            break;
        case 'boolean':
            type = 'boolean';
            break;
        case 'json':
            type = 'any';
            break;
        case 'date':
        case 'datetime':
        case 'time':
            type = 'string';
            break;
        case 'enumeration':
            type = `${(0, change_case_1.pascalCase)(modelName)}${(0, change_case_1.pascalCase)(attributeName)}Enum`;
            break;
        case 'relation':
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            const array = ['oneToMany', 'manyToMany'].includes(attrRelation.relation)
                ? '[]'
                : '';
            return isDto ? `${(0, change_case_1.pascalCase)(target.collectionName)}Dto${array}` : '';
        default:
            throw new common_1.BadRequestException(`Current attribute type ${attribute.type} is not supported`);
    }
    return attribute.required ? type : `Nullable<${type}>`;
};
const generateOpenApiType = (attribute, contentTypesSchema, isDto = true) => {
    switch (attribute.type) {
        case 'string':
        case 'password':
        case 'text':
        case 'richtext':
            return `'string'`;
        case 'integer':
        case 'bigint':
        case 'float':
        case 'decimal':
            return `'number'`;
        case 'boolean':
            return `'boolean'`;
        case 'json':
            return `'object'`;
        case 'date':
        case 'datetime':
        case 'time':
            return `'string'`;
        case 'enumeration':
            return `'string'`;
        case 'relation':
            const attrRelation = attribute;
            const target = contentTypesSchema[attrRelation.target];
            return isDto ? `() => ${(0, change_case_1.pascalCase)(target.collectionName)}Dto` : '';
        default:
            throw new common_1.BadRequestException(`Current attribute type ${attribute.type} is not supported`);
    }
};
const generateValidateType = (attribute, attributeName, modelName) => {
    var _a;
    switch (attribute.type) {
        case 'string': {
            const attrStr = attribute;
            return `${attrStr.regex ? `@Matches(${new RegExp(attrStr.regex)})\n` : ''}${attrStr.required ? '@IsNotEmpty()\n' : ''}@MaxLength(${(_a = attrStr.maxLength) !== null && _a !== void 0 ? _a : 255})${attrStr.minLength ? `\n@MinLength(${attrStr.minLength})` : ''}
@IsString()`;
        }
        case 'password': {
            return `@MaxLength(255)
@IsString()`;
        }
        case 'text':
        case 'richtext': {
            const attrStr = attribute;
            return `${attrStr.regex ? `@Matches(${new RegExp(attrStr.regex)})\n` : ''}${attrStr.required ? '@IsNotEmpty()\n' : ''}${attrStr.maxLength ? `@MaxLength(${attrStr.maxLength})\n` : ''}${attrStr.minLength ? `\n@MinLength(${attrStr.minLength})` : ''}
@IsString()`;
        }
        case 'integer':
        case 'bigint': {
            const attrNumber = attribute;
            return `${attrNumber.max ? `@Max(${attrNumber.max})\n` : ''}${attrNumber.min ? `@Min(${attrNumber.min})\n` : ''}@IsInt()`;
        }
        case 'float': {
            const attrNumber = attribute;
            return `${attrNumber.max ? `@Max(${attrNumber.max})\n` : ''}${attrNumber.min ? `@Min(${attrNumber.min})\n` : ''}@IsNumber()`;
        }
        case 'decimal': {
            const attrDecimal = attribute;
            return `${attrDecimal.max ? `@Max(${attrDecimal.max})\n` : ''}${attrDecimal.min ? `@Min(${attrDecimal.min})\n` : ''}@IsNumber({ maxDecimalPlaces: ${attrDecimal.scale}})`;
        }
        case 'boolean':
            return '@IsBoolean()';
        case 'json':
            return '@IsObject()';
        case 'date':
        case 'datetime':
        case 'time':
            return '@IsDateStringISO()';
        case 'enumeration':
            return `@IsEnum(${(0, change_case_1.pascalCase)(modelName)}${(0, change_case_1.pascalCase)(attributeName)}Enum)`;
        default:
            throw new common_1.BadRequestException(`Current attribute type ${attribute.type} is not supported`);
    }
};
const generateContentTypeDtoIndexContent = (contentType) => {
    const template = `export * from './create-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
export * from './update-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
export * from './admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';
export * from './create-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
export * from './update-admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.input';
export * from './${(0, change_case_1.paramCase)(contentType.collectionName)}.dto';`;
    return template;
};
const generateContentTypeModuleIndexContent = (contentType) => {
    const template = `export * from './dto';
export * from './admin-${(0, change_case_1.paramCase)(contentType.collectionName)}.controller';
export * from './${(0, change_case_1.paramCase)(contentType.collectionName)}.controller';
export * from './${(0, change_case_1.paramCase)(contentType.collectionName)}.service';`;
    return template;
};
function importContentTypeIntoAppModule(rootFolder, contentType) {
    const appModulePath = path.join(rootFolder, 'src/app.module.ts');
    let appModuleContent = fs.readFileSync(appModulePath, {
        encoding: 'utf8',
    });
    const importStr = `import { ${(0, change_case_1.pascalCase)(contentType.collectionName)}Module } from '@content-type/${(0, change_case_1.paramCase)(contentType.collectionName)}/${(0, change_case_1.paramCase)(contentType.collectionName)}.module';`;
    const moduleName = `${(0, change_case_1.pascalCase)(contentType.collectionName)}Module`;
    if (!appModuleContent.includes(moduleName)) {
        const regex = /@Module\({\n  imports: \[([a-zA-Z0-9,\s.()]*)\]/gm;
        const m = regex.exec(appModuleContent);
        if (m && m.length > 1) {
            const text = m[1];
            appModuleContent =
                appModuleContent.slice(0, appModuleContent.indexOf(text) + text.length) +
                    `${text.trim().endsWith(',') ? '' : ','}\n    ` +
                    moduleName +
                    ',\n' +
                    appModuleContent.slice(appModuleContent.indexOf(text) + text.length);
        }
    }
    if (!appModuleContent.includes(importStr)) {
        const regex = /import [a-zA-Z0-9, .(){}''""@\/\-_]*;/gm;
        let m;
        let t;
        while ((m = regex.exec(appModuleContent)) !== null) {
            t = m;
            if (m.index === regex.lastIndex) {
                regex.lastIndex++;
            }
        }
        if (t) {
            appModuleContent =
                appModuleContent.slice(0, appModuleContent.indexOf(t[0]) + t[0].length) +
                    '\n' +
                    importStr +
                    appModuleContent.slice(appModuleContent.indexOf(t[0]) + t[0].length);
        }
    }
    fs.writeFileSync(`${appModulePath}`, appModuleContent, {
        encoding: 'utf-8',
    });
}
const generateContentTypeAttributeStringDto = (attributeName, attribute, contentType) => {
    const attrStr = attribute;
    return `@ApiProperty({ type: 'string', required: true, nullable: ${attrStr.required ? 'true' : 'false'}, ${attrStr.minLength ? `minLength: ${attrStr.minLength}, ` : ''}${attrStr.maxLength ? `maxLength: ${attrStr.maxLength}, ` : ''} })
@Expose()
public readonly ${attributeName}: ${attrStr.required ? 'string' : ' Nullable<string>'};`;
};
const generateContentTypeAttributeNumberDto = (attributeName, attribute, contentType) => {
    const attrNum = attribute;
    return `@ApiProperty({ type: 'number', required: true, nullable: ${attrNum.required ? 'true' : 'false'}, ${attrNum.min ? `minimum: ${attrNum.min}, ` : ''}${attrNum.max ? `maximum: ${attrNum.max}, ` : ''}})
@Expose()
public readonly ${attributeName}: ${attrNum.required ? 'number' : ' Nullable<number>'};`;
};
const generateContentTypeAttributeBoolenDto = (attributeName, attribute, contentType) => {
    const attrNum = attribute;
    return `@ApiProperty({ type: 'number', required: true, nullable: ${attrNum.required ? 'true' : 'false'}})
@Expose()
public readonly ${attributeName}: ${attrNum.required ? 'boolean' : ' Nullable<boolean>'};`;
};
const generateContentTypeAttributeEnumDto = (attributeName, attribute, contentType) => {
    const attrNum = attribute;
    return `@ApiProperty({ type: 'number', required: true, nullable: ${attrNum.required ? 'true' : 'false'}})
@Expose()
public readonly ${attributeName}: ${attrNum.required ? 'boolean' : ' Nullable<boolean>'};`;
};
//# sourceMappingURL=generate-content-type-module.js.map