/// 벤더(제조사) 도메인 엔티티
///
/// - SRP: 벤더의 속성 표현만 담당
/// - data/presentation 레이어에 의존하지 않음
class Vendor {
  Vendor({
    this.id,
    required this.vendorCode,
    required this.vendorName,
    this.isActive = true,
    this.isDeleted = false,
    this.note,
    this.createdAt,
    this.updatedAt,
  });

  /// PK (DB bigint), 신규 생성 시 null
  final int? id;

  /// 벤더코드 (부분유니크: is_deleted=false)
  final String vendorCode;

  /// 벤더명
  final String vendorName;

  /// 사용 여부
  final bool isActive;

  /// 소프트 삭제 여부
  final bool isDeleted;

  /// 비고
  final String? note;

  /// 생성/변경 일시 (선택)
  final DateTime? createdAt;
  final DateTime? updatedAt;

  Vendor copyWith({
    int? id,
    String? vendorCode,
    String? vendorName,
    bool? isActive,
    bool? isDeleted,
    String? note,
    DateTime? createdAt,
    DateTime? updatedAt,
  }) {
    return Vendor(
      id: id ?? this.id,
      vendorCode: vendorCode ?? this.vendorCode,
      vendorName: vendorName ?? this.vendorName,
      isActive: isActive ?? this.isActive,
      isDeleted: isDeleted ?? this.isDeleted,
      note: note ?? this.note,
      createdAt: createdAt ?? this.createdAt,
      updatedAt: updatedAt ?? this.updatedAt,
    );
  }
}

/// 벤더 신규/수정 입력 모델
///
/// - code는 생성 시 필수, 수정 시 읽기 전용이지만 API 전송을 위해 포함
class VendorInput {
  VendorInput({
    required this.vendorCode,
    required this.vendorName,
    this.isActive = true,
    this.note,
  });

  final String vendorCode;
  final String vendorName;
  final bool isActive;
  final String? note;

  Map<String, dynamic> toPayload() {
    return {
      'vendor_code': vendorCode,
      'vendor_name': vendorName,
      'is_active': isActive,
      'note': note,
    };
  }
}
