package lu.foyer package clients import zio.* import java.util.UUID object ClientHandlers: val layer: ULayer[List[CommandHandler[ClientCommand, ClientEvent, ClientState]]] = ZLayer.succeed( List( CreateHandler, UpdateHandler, DisableHandler ) ) object CreateHandler extends CommandHandlerCreate[ClientCommand.Create, ClientEvent.Created]: val name = "create" def onCommand(entityId: UUID, command: ClientCommand.Create): Task[ClientEvent.Created] = ZIO.succeed( ClientEvent.Created( command.lastName, command.firstName, command.birthDate, command.drivingLicenseDate, command.phoneNumber, command.email, command.address ) ) object UpdateHandler extends CommandHandlerUpdate[ClientCommand.Update, ClientEvent.Updated, ClientState.Actif]: val name = "update" def onCommand(entityId: UUID, state: ClientState.Actif, command: ClientCommand.Update) : Task[ClientEvent.Updated] = ZIO.succeed( ClientEvent.Updated( command.lastName, command.firstName, command.birthDate, command.drivingLicenseDate, command.phoneNumber, command.email, command.address ) ) object DisableHandler extends CommandHandlerUpdate[ClientCommand.Disable, ClientEvent.Disabled, ClientState.Actif]: val name = "disable" def onCommand(entityId: UUID, state: ClientState.Actif, command: ClientCommand.Disable) : Task[ClientEvent.Disabled] = ZIO.succeed(ClientEvent.Disabled(command.reason))