import { DomainRole } from './Domain'; import ApiClientError from '../errors/ApiClientError'; export type LocationACLProfileResponse = { id: string; email: string; name: string; thumbnail_url?: string; domain_id: string; domain_role: DomainRole; }; export type LocationACLResponse = { id: string; grant_profile: LocationACLProfileResponse; grant_domain_id: string | null; grant_scope: string | null; grant_folder_path: string[] | null; read_grant: boolean; update_grant: boolean; delete_grant: boolean; custom_access_grants: string[]; share_grant: boolean; full_grant: boolean; }; export type LocationACLPendingInviteResponse = { invite_id: string; email: string; name: string; domain_role: DomainRole; last_sent_at?: string; }; export type LocationResponse = { id: string; name: string; external_id: string; description: string; created_at: string; updated_at: string; acl: LocationACLResponse[]; acl_pending_invites: LocationACLPendingInviteResponse[]; }; export type LocationACLProfile = { id: string; email: string; name: string; thumbnailUrl?: string | null; domainId: string; domainRole: DomainRole; }; export type LocationACL = { id: string; grantProfile: LocationACLProfile; grantDomainId: string | null; grantScope: string | null; grantFolderPath: string[] | null; readGrant: boolean; updateGrant: boolean; deleteGrant: boolean; customAccessGrants: string[]; shareGrant: boolean; fullGrant: boolean; }; export type LocationACLPendingInvite = { inviteId: string; email: string; name: string; domainRole: DomainRole; lastSentAt?: string; }; export type Location = { id: string; name: string; description: string; externalId: string; createdAt: string; updatedAt: string | null; acl: LocationACL[]; aclPendingInvites: LocationACLPendingInvite[]; }; export type CreateLocationRequest = { name: string; description: string; externalId?: string; }; export type GetLocationsRequest = undefined; export type GetLocationsResponse = { total: number; data: LocationResponse[]; }; export type GetLocations = Location[]; export type EditLocationRequest = Partial; export type CreateLocationResponse = LocationResponse; export type CreateLocation = Location; export type EditLocationResponse = LocationResponse; export type EditLocation = Location; export type DeleteLocationRequest = undefined; export type DeleteLocationResponse = void; export type DeleteLocation = void; export type GetPendingLocationsRequest = undefined; export type GetPendingLocationsResponse = { id: string; name: string; description: string; created_at: string; updated_at: string; active_users: LocationACLProfileResponse[]; pending_users: LocationACLPendingInviteResponse[]; }[]; export type GetPendingLocations = { id: string; name: string; description: string; createdAt: string; updatedAt: string; activeUsers: LocationACLProfile[]; pendingUsers: LocationACLPendingInvite[]; }[]; export type InviteUserToLocation = { profileId: string; inviteId: string; }; export type InviteUserToLocationRequest = { profile_id: string; invite_id: string; }; export type InviteUserToLocationResponse = LocationResponse; export type RemoveUserFromLocation = InviteUserToLocation; export type RemoveUserFromLocationRequest = InviteUserToLocationRequest; export type RemoveUserFromLocationResponse = LocationResponse; export type MoveDevicesToAnotherLocation = { deviceIds: string[]; }; export type MoveDevicesToAnotherLocationRequest = { device_ids: string[]; }; export type MoveDevicesToAnotherLocationResponse = void; interface LocationConflictErrorResponse { message: string; existing_location_name: string; } export class LocationExternalIDConflictError extends ApiClientError { public existingLocationName?: string; constructor(responseText?: string) { let existingLocationName: string | undefined; try { if (responseText) { const parsed = JSON.parse( responseText, ) as LocationConflictErrorResponse; if (parsed.existing_location_name) { existingLocationName = parsed.existing_location_name; } } } catch { // If parsing fails, existingLocationName remains undefined } super(409, 'Location with this external ID already exists'); this.name = 'LocationExternalIDConflict'; this.existingLocationName = existingLocationName; } }