/**
 * Profile use cases. Thin orchestration over ports; ownership/role checks
 * happen in the API layer before these run.
 */
import type { ProfileRepository } from '../domain/ports.js';
import type {
  CustomerListOptions,
  CustomerListResult,
  CustomerSummary,
  Profile,
  ProfilePatch,
} from '../domain/profile.js';

export class GetProfile {
  constructor(private readonly profiles: ProfileRepository) {}
  async execute(userId: string): Promise<Profile | undefined> {
    return this.profiles.findByUserId(userId);
  }
}

export class UpdateProfile {
  constructor(private readonly profiles: ProfileRepository) {}
  async execute(userId: string, patch: ProfilePatch): Promise<Profile> {
    return this.profiles.upsert(userId, patch);
  }
}

export class ListProfiles {
  constructor(private readonly profiles: ProfileRepository) {}
  async execute(): Promise<Profile[]> {
    return this.profiles.list();
  }
}

export class ListCustomers {
  constructor(private readonly profiles: ProfileRepository) {}
  async execute(opts: CustomerListOptions): Promise<CustomerListResult> {
    return this.profiles.listCustomers(opts);
  }
}

export class GetCustomer {
  constructor(private readonly profiles: ProfileRepository) {}
  async execute(userId: string): Promise<CustomerSummary | undefined> {
    return this.profiles.findCustomerById(userId);
  }
}
