import { ApiProperty } from '@nestjs/swagger';
import { TrainCheckpointKind } from '@edr/types';
import {
  IsEnum,
  IsInt,
  IsISO8601,
  IsOptional,
  IsString,
  MaxLength,
  Min,
} from 'class-validator';

import { IsNotBackdated } from '../../../common/validators/is-not-backdated.validator';

export class RecordCheckpointDto {
  @ApiProperty({ description: 'Station position along the route (0 = origin).' })
  @IsInt()
  @Min(0)
  sequenceNo!: number;

  @ApiProperty({ enum: TrainCheckpointKind, required: false })
  @IsOptional()
  @IsEnum(TrainCheckpointKind)
  kind?: TrainCheckpointKind;

  /**
   * A checkpoint records where the train is as staff observe it, and the final
   * one arrives the schedule — so a backdated value rewrites the journey after
   * the fact. Only "now" is accepted; omit the field and the service stamps it.
   */
  @ApiProperty({
    required: false,
    description: 'ISO timestamp; defaults to now. Cannot be earlier than now.',
  })
  @IsOptional()
  @IsISO8601()
  @IsNotBackdated()
  occurredAt?: string;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  @MaxLength(500)
  note?: string;
}
