import '../../domain/entities/product_stage_entity.dart';

/// Product stage model for data layer
/// Represents a product at a specific production stage
class ProductStageModel extends ProductStageEntity {
  const ProductStageModel({
    required super.productId,
    required super.productStageId,
    required super.actionTypeId,
    required super.passedQuantity,
    required super.issuedQuantity,
    required super.issuedQuantityWeight,
    required super.passedQuantityWeight,
    required super.stageName,
    required super.createdDate,
    super.productName,
    super.productCode,
    super.stageId,
  });

  /// Create ProductStageModel from JSON
  factory ProductStageModel.fromJson(Map<String, dynamic> json) {
    return ProductStageModel(
      productId: json['ProductId'] as int,
      productStageId: json['ProductStageId'] as int?,
      actionTypeId: json['ActionTypeId'] as int?,
      passedQuantity: json['PassedQuantity'] as int,
      issuedQuantity: json['IssuedQuantity'] as int,
      issuedQuantityWeight: (json['IssuedQuantityWeight'] as num).toDouble(),
      passedQuantityWeight: (json['PassedQuantityWeight'] as num).toDouble(),
      stageName: json['StageName'] as String?,
      createdDate: json['CreatedDate'] as String,
      productName: json['ProductName'] as String? ?? '',
      productCode: json['ProductCode'] as String? ?? '',
      stageId: json['StageId'] as int?,
    );
  }

  /// Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'ProductId': productId,
      'ProductStageId': productStageId,
      'ActionTypeId': actionTypeId,
      'PassedQuantity': passedQuantity,
      'IssuedQuantity': issuedQuantity,
      'IssuedQuantityWeight': issuedQuantityWeight,
      'PassedQuantityWeight': passedQuantityWeight,
      'StageName': stageName,
      'CreatedDate': createdDate,
      'ProductName': productName,
      'ProductCode': productCode,
      'StageId': stageId,
    };
  }

  /// Convert to entity
  ProductStageEntity toEntity() {
    return ProductStageEntity(
      productId: productId,
      productStageId: productStageId,
      actionTypeId: actionTypeId,
      passedQuantity: passedQuantity,
      issuedQuantity: issuedQuantity,
      issuedQuantityWeight: issuedQuantityWeight,
      passedQuantityWeight: passedQuantityWeight,
      stageName: stageName,
      createdDate: createdDate,
      productName: productName,
      productCode: productCode,
      stageId: stageId,
    );
  }

  @override
  String toString() {
    return 'ProductStageModel(productId: $productId, stageName: $stageName, passedQuantity: $passedQuantity)';
  }
}
