import 'package:freezed_annotation/freezed_annotation.dart';

part 'user_dto.freezed.dart';
part 'user_dto.g.dart';

enum UserRole {
  @JsonValue('admin')
  admin,
  @JsonValue('manager')
  manager,
  @JsonValue('staff')
  staff,
}

@freezed
class UserDto with _$UserDto {
  const factory UserDto({
    required int id,
    required String username,
    required String email,
    required String name,
    String? phone,
    required String role,
    @JsonKey(name: 'company_id') int? companyId,
    @JsonKey(name: 'branch_id') int? branchId,
    @JsonKey(name: 'is_active') required bool isActive,
    @JsonKey(name: 'created_at') required DateTime createdAt,
    @JsonKey(name: 'updated_at') required DateTime updatedAt,
  }) = _UserDto;

  factory UserDto.fromJson(Map<String, dynamic> json) =>
      _$UserDtoFromJson(json);
}

@freezed
class CreateUserRequest with _$CreateUserRequest {
  const factory CreateUserRequest({
    required String username,
    required String email,
    required String password,
    required String name,
    String? phone,
    required String role,
    @JsonKey(name: 'company_id') int? companyId,
    @JsonKey(name: 'branch_id') int? branchId,
  }) = _CreateUserRequest;

  factory CreateUserRequest.fromJson(Map<String, dynamic> json) =>
      _$CreateUserRequestFromJson(json);
}

@freezed
class UpdateUserRequest with _$UpdateUserRequest {
  const factory UpdateUserRequest({
    String? name,
    String? email,
    String? password,
    String? phone,
    String? role,
    @JsonKey(name: 'company_id') int? companyId,
    @JsonKey(name: 'branch_id') int? branchId,
  }) = _UpdateUserRequest;

  factory UpdateUserRequest.fromJson(Map<String, dynamic> json) =>
      _$UpdateUserRequestFromJson(json);
}

@freezed
class ChangeStatusRequest with _$ChangeStatusRequest {
  const factory ChangeStatusRequest({
    @JsonKey(name: 'is_active') required bool isActive,
  }) = _ChangeStatusRequest;

  factory ChangeStatusRequest.fromJson(Map<String, dynamic> json) =>
      _$ChangeStatusRequestFromJson(json);
}

@freezed
class ChangePasswordRequest with _$ChangePasswordRequest {
  const factory ChangePasswordRequest({
    @JsonKey(name: 'current_password') required String currentPassword,
    @JsonKey(name: 'new_password') required String newPassword,
  }) = _ChangePasswordRequest;

  factory ChangePasswordRequest.fromJson(Map<String, dynamic> json) =>
      _$ChangePasswordRequestFromJson(json);
}

@freezed
class UserListDto with _$UserListDto {
  const factory UserListDto({
    required List<UserDto> users,
    required int total,
    required int page,
    @JsonKey(name: 'per_page') required int perPage,
    @JsonKey(name: 'total_pages') required int totalPages,
  }) = _UserListDto;

  factory UserListDto.fromJson(Map<String, dynamic> json) =>
      _$UserListDtoFromJson(json);
}

