/**
 * Address use cases. Every operation is scoped to the owner's userId.
 */
import type { AddressRepository } from '../domain/ports.js';
import type { Address, AddressPatch, NewAddress } from '../domain/address.js';

export class ListAddresses {
  constructor(private readonly addresses: AddressRepository) {}
  async execute(userId: string): Promise<Address[]> {
    return this.addresses.listByUserId(userId);
  }
}

export class CreateAddress {
  constructor(private readonly addresses: AddressRepository) {}
  async execute(userId: string, input: NewAddress): Promise<Address> {
    return this.addresses.create(userId, input);
  }
}

export class UpdateAddress {
  constructor(private readonly addresses: AddressRepository) {}
  async execute(
    userId: string,
    addressId: string,
    patch: AddressPatch,
  ): Promise<Address | undefined> {
    return this.addresses.update(userId, addressId, patch);
  }
}

export class DeleteAddress {
  constructor(private readonly addresses: AddressRepository) {}
  async execute(userId: string, addressId: string): Promise<boolean> {
    return this.addresses.delete(userId, addressId);
  }
}
