import 'package:pshared/data/dto/permissions/data/permission.dart';
import 'package:pshared/data/mapper/permissions/action_effect.dart';
import 'package:pshared/models/permissions/data/permission.dart';
import 'package:pshared/models/permissions/data/policy.dart';


extension PermissionMapper on Permission {
  PermissionDTO toDTO() {
    return PermissionDTO(
        roleDescriptionRef: policy.roleDescriptionRef,
        organizationRef: policy.organizationRef,
        descriptionRef: policy.descriptionRef,
        objectRef: policy.objectRef,
        effect: policy.effect.toDTO(),
        accountRef: accountRef,
    );
  }
}

extension PermissionDTOMapper on PermissionDTO {
  Permission toDomain() {
    return Permission(
      policy: Policy(
        roleDescriptionRef: roleDescriptionRef, 
        organizationRef: organizationRef, 
        descriptionRef: descriptionRef, 
        objectRef: objectRef, 
        effect: effect.toDomain(),
      ),
      accountRef: accountRef,
    );
  }
}
