import { PartialType, OmitType } from '@nestjs/mapped-types';
import { IsIn, IsOptional } from 'class-validator';
import { CreateLeadDto } from './create-lead.dto';
import { LeadStatus } from './../entities/lead.entity';

/**
 * Editing an existing lead. Unlike create, 'Converted' IS a valid value here
 * — but only when the lead is already Converted (i.e. saving it as-is).
 * The service enforces "can't flip INTO Converted through this endpoint";
 * that transition must go through your convert-to-client flow.
 *
 * 🆕 `assigned_to` is omitted. Handing a lead to someone else now goes
 * through POST /leads/:id/assign, which checks the 'assign' permission and
 * fires the notification + email. If a stray PATCH could still change the
 * owner, the two paths would drift apart and some handovers would land
 * silently. `client_group` IS editable here.
 */
export class UpdateLeadDto extends PartialType(
  OmitType(CreateLeadDto, [
    'status',
    'override_duplicate',
    'assigned_to',
  ] as const),
) {
  @IsOptional()
  @IsIn([
    LeadStatus.NEW,
    LeadStatus.INTERESTED,
    LeadStatus.LOST,
    LeadStatus.CONVERTED,
  ])
  status?: LeadStatus;
}
