import 'package:pshared/data/dto/organization.dart';
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/organization/bound.dart';
import 'package:pshared/models/organization/organization.dart';
import 'package:pshared/models/permissions/bound.dart';
import 'package:pshared/models/storable.dart';


extension OrganizationMapper on Organization {
  OrganizationDTO toDTO() => OrganizationDTO(
    id: storable.id,
    createdAt: storable.createdAt,
    updatedAt: storable.updatedAt,
    name: describable.name,
    description: describable.description,
    timeZone: timeZone,
    logoUrl: logoUrl,
    organizationRef: permissionBound.organizationRef,
    permissionRef: permissionBound.permissionRef,
    tenantRef: tenantRef,
  );
}

extension OrganizationDTOMapper on OrganizationDTO {
  Organization toDomain() => Organization(
    storable: newStorable(id: id, createdAt: createdAt, updatedAt: updatedAt),
    describable: newDescribable(name: name, description: description),
    timeZone: timeZone,
    logoUrl: logoUrl,
    permissionBound: newPermissionBound(
      organizationBound: newOrganizationBound(organizationRef: organizationRef),
      permissionRef: permissionRef,
    ),
    tenantRef: tenantRef,
  );
}
