import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
import {
  DataSchedulingDefaultEntity,
  DataSchedulingEntity,
} from '../../domain/entities/data-scheduling.entity';
import { IsString, ValidateIf } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { BaseCoreDto } from 'src/core/modules/infrastructure/dto/base-core.dto';
import { Transform } from 'class-transformer';
import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto';

export class CreateDataSchedulingDto
  extends BaseStatusDto
  implements DataSchedulingEntity
{
  @ApiProperty({ name: 'name', required: true, example: 'Morning' })
  @IsString()
  name: string;

  @ApiProperty({ type: 'integer', required: true, example: 80 })
  @Transform((body) => {
    return typeof body.value == 'string' ? Number(body.value) : body.value;
  })
  @ValidateIf((body) => body.indexing_key)
  indexing_key: number;

  @ApiProperty({
    type: Date,
    required: true,
    example: '2024-01-01',
  })
  schedule_date_from: Date;

  @ApiProperty({
    type: Date,
    required: true,
    example: '2024-01-02',
  })
  schedule_date_to: Date;
}

export class EditDataSchedulingDto
  extends BaseStatusDto
  implements DataSchedulingEntity
{
  @ApiProperty({ name: 'name', example: 'Morning' })
  @IsString()
  @ValidateIf((body) => body.name)
  name: string;

  @ApiProperty({ type: 'integer', required: true, example: 80 })
  @Transform((body) => {
    return typeof body.value == 'string' ? Number(body.value) : body.value;
  })
  @ValidateIf((body) => body.indexing_key)
  indexing_key: number;

  @ApiProperty({
    type: Date,
    required: true,
    example: '2025-01-01',
  })
  schedule_date_from: Date;

  @ApiProperty({
    type: Date,
    required: true,
    example: '2025-01-02',
  })
  schedule_date_to: Date;
}

export class EditDataSchedulingDefaultDto
  extends BaseDto
  implements DataSchedulingDefaultEntity
{
  @ApiProperty({ type: 'integer', required: true })
  @Transform((body) => {
    return typeof body.value == 'string' ? Number(body.value) : body.value;
  })
  @ValidateIf((body) => body.default_value)
  default_value: number;
}

export class SetupDataSchedulingDto {
  // @ApiProperty({ type: 'string', required: true, example: '2025-01-01' })
  // date: Date;
}
