import 'package:equatable/equatable.dart';
import 'package:flux/core/utils/extensions.dart';

class BrandModel extends Equatable {
  final String? id;
  final String name;
  final String companyId;
  final bool isActive;
  final DateTime? createdAt;

  const BrandModel({
    this.id,
    required this.name,
    required this.companyId,
    this.isActive = true,
    this.createdAt,
  });

  factory BrandModel.fromJson(Map<String, dynamic> json) {
    return BrandModel(
      id: json['id'] as String,
      name: (json['name'] as String).myFormat(),
      companyId: json['company_id'] as String,
      isActive: json['is_active'] as bool? ?? true,
      createdAt: json['created_at'] != null
          ? DateTime.parse(json['created_at'])
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      if (id != null) 'id': id,
      'name': name.toLowerCase().trim(),
      'company_id': companyId,
      'is_active': isActive,
    };
  }

  BrandModel copyWith({
    String? id,
    String? name,
    String? companyId,
    bool? isActive,
    DateTime? createdAt,
  }) {
    return BrandModel(
      id: id ?? this.id,
      name: name ?? this.name,
      companyId: companyId ?? this.companyId,
      isActive: isActive ?? this.isActive,
      createdAt: createdAt ?? this.createdAt,
    );
  }

  @override
  List<Object?> get props => [id, name, companyId, isActive, createdAt];
}
