import { operation, buildingBase, buildingCommonMethods, buildingView, requestBodySchema, response200, response500, security, statusSchema, tags, } from '../../chunks.ts'; const base = buildingBase('Embassy'); const buildingIdRequestBody = requestBodySchema({ type: 'object', required: ['building_id'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' } }, }); const optionalMessageRequestBody = (extraRequired: string[] = [], extraProperties: object = {}) => requestBodySchema({ type: 'object', required: ['building_id', ...extraRequired], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, message: { type: 'string', description: 'An optional personalised message included with the action.', }, ...extraProperties, }, }); // This empire's alliance, as returned nested under `alliance_status` on `view` and (flattened // alongside `status`) by get_alliance_status. const allianceStatusProperties = { id: { type: 'integer' }, name: { type: 'string' }, members: { type: 'array', items: { type: 'object', properties: { empire_id: { type: 'integer' }, name: { type: 'string' } }, }, }, leader_id: { type: 'integer' }, forum_uri: { type: 'string' }, description: { type: 'string' }, announcements: { type: 'string' }, date_created: { type: 'string' }, }; // This is the module where alliance *management* (create/dissolve/invite/leave/stash/ // propositions) lives, per the docs — the Alliance module itself only exposes read-only lookups. export const embassy = { ...buildingCommonMethods(base), ...buildingView(base, { alliance_status: { type: 'object', description: 'Present only when this empire is in an alliance.', properties: allianceStatusProperties, }, }), [`${base}/create_alliance`]: { post: { ...tags(base), ...security(), ...operation('Create alliance.', 'Creates a new alliance with this empire as leader.'), ...requestBodySchema({ type: 'object', required: ['building_id', 'name'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, name: { type: 'string', minLength: 3, maxLength: 30, description: 'A unique alliance name, 3-30 characters, no profanity or restricted characters.', }, }, }), responses: { ...response200('Creates a new alliance with this empire as leader.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/get_alliance_status`]: { post: { ...tags(base), ...security(), ...operation('Get alliance status.', "Returns this empire's alliance data."), ...buildingIdRequestBody, responses: { ...response200("Returns this empire's alliance data.", { type: 'object', required: ['status'], properties: { ...allianceStatusProperties, status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/dissolve_alliance`]: { post: { ...tags(base), ...security(), ...operation( 'Dissolve alliance.', 'Leader-only. Disbands the alliance and converts its space stations to asteroids.' ), ...buildingIdRequestBody, responses: { ...response200( 'Leader-only. Disbands the alliance and converts its space stations to asteroids.', { type: 'object', required: ['status'], properties: { status: statusSchema() } } ), ...response500(), }, }, }, [`${base}/update_alliance`]: { post: { ...tags(base), ...security(), ...operation('Update alliance.', 'Leader-only. Updates alliance metadata.'), ...requestBodySchema({ type: 'object', required: ['building_id', 'params'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, params: { type: 'object', description: 'The alliance properties to update. Any or all of forum_uri, description, announcements.', properties: { forum_uri: { type: 'string' }, description: { type: 'string' }, announcements: { type: 'string' }, }, }, }, }), responses: { ...response200('Leader-only. Updates alliance metadata.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/send_invite`]: { post: { ...tags(base), ...security(), ...operation('Send invite.', 'Leader-only. Invites an empire to join the alliance.'), ...optionalMessageRequestBody(['invitee_id'], { invitee_id: { type: 'integer', description: 'The unique id of the empire to invite.' }, }), responses: { ...response200('Leader-only. Invites an empire to join the alliance.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/withdraw_invite`]: { post: { ...tags(base), ...security(), ...operation('Withdraw invite.', 'Leader-only. Withdraws a pending invite.'), ...optionalMessageRequestBody(['invite_id'], { invite_id: { type: 'integer', description: 'The unique id of the invitation.' }, }), responses: { ...response200('Leader-only. Withdraws a pending invite.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/get_pending_invites`]: { post: { ...tags(base), ...security(), ...operation( 'Get pending invites.', 'Leader-only. Lists outstanding invites sent by the alliance.' ), ...buildingIdRequestBody, responses: { ...response200('Leader-only. Lists outstanding invites sent by the alliance.', { type: 'object', required: ['invites', 'status'], properties: { invites: { type: 'array', items: { type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' }, empire_id: { type: 'integer' }, }, }, }, status: statusSchema(), }, }), ...response500(), }, }, }, [`${base}/accept_invite`]: { post: { ...tags(base), ...security(), ...operation('Accept invite.', 'Accepts an invite to join an alliance.'), ...optionalMessageRequestBody(['invite_id'], { invite_id: { type: 'integer', description: 'The unique id of the invitation.' }, }), responses: { ...response200('Accepts an invite to join an alliance.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/reject_invite`]: { post: { ...tags(base), ...security(), ...operation('Reject invite.', 'Declines an invite to join an alliance.'), ...optionalMessageRequestBody(['invite_id'], { invite_id: { type: 'integer', description: 'The unique id of the invitation.' }, }), responses: { ...response200('Declines an invite to join an alliance.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/get_my_invites`]: { post: { ...tags(base), ...security(), ...operation('Get my invites.', 'Lists invites this empire has received.'), ...buildingIdRequestBody, responses: { ...response200('Lists invites this empire has received.', { type: 'object', required: ['invites', 'status'], properties: { invites: { type: 'array', items: { type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' }, alliance_id: { type: 'integer' }, }, }, }, status: statusSchema(), }, }), ...response500(), }, }, }, [`${base}/leave_alliance`]: { post: { ...tags(base), ...security(), ...operation('Leave alliance.', 'Leaves the current alliance.'), ...optionalMessageRequestBody(), responses: { ...response200('Leaves the current alliance.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/expel_member`]: { post: { ...tags(base), ...security(), ...operation('Expel member.', 'Leader-only. Removes a member from the alliance.'), ...optionalMessageRequestBody(['empire_id'], { empire_id: { type: 'integer', description: 'The unique id of the member to remove.' }, }), responses: { ...response200('Leader-only. Removes a member from the alliance.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/assign_alliance_leader`]: { post: { ...tags(base), ...security(), ...operation( 'Assign alliance leader.', 'Leader-only. Transfers alliance leadership to another current member.' ), ...requestBodySchema({ type: 'object', required: ['building_id', 'new_leader_id'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, new_leader_id: { type: 'integer', description: 'The unique id of the empire to make leader. Must already be a member of the alliance.', }, }, }), responses: { ...response200('Leader-only. Transfers alliance leadership to another current member.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/view_stash`]: { post: { ...tags(base), ...security(), ...operation('View stash.', "Returns the alliance stash's contents."), ...buildingIdRequestBody, responses: { ...response200("Returns the alliance stash's contents.", { type: 'object', required: ['stash', 'stored', 'max_exchange_size', 'exchanges_remaining_today', 'status'], properties: { stash: { type: 'object', description: "The alliance stash's contents, keyed by resource name.", additionalProperties: { type: 'integer' }, }, stored: { type: 'object', description: "The calling planet's own storable resources, keyed by resource name.", additionalProperties: { type: 'integer' }, }, max_exchange_size: { type: 'integer' }, exchanges_remaining_today: { type: 'integer' }, status: statusSchema(), }, }), ...response500(), }, }, }, [`${base}/donate_to_stash`]: { post: { ...tags(base), ...security(), ...operation('Donate to stash.', 'Donates resources to the alliance stash.'), ...requestBodySchema({ type: 'object', required: ['building_id', 'donation'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, donation: { type: 'object', description: 'Resource name to quantity, e.g. {"water": 4500, "bread": 5000}. Waste is not allowed.', additionalProperties: { type: 'integer' }, }, }, }), responses: { ...response200('Donates resources to the alliance stash.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/exchange_with_stash`]: { post: { ...tags(base), ...security(), ...operation('Exchange with stash.', 'Exchanges resources with the alliance stash.'), ...requestBodySchema({ type: 'object', required: ['building_id', 'donation', 'request'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, donation: { type: 'object', description: 'Must equal request in total value. Waste is not allowed.', additionalProperties: { type: 'integer' }, }, request: { type: 'object', description: 'Resource name to quantity to pull from the stash. Total value must equal the donation total.', additionalProperties: { type: 'integer' }, }, }, }), responses: { ...response200('Exchanges resources with the alliance stash.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, [`${base}/view_propositions`]: { post: { ...tags(base), ...security(), ...operation('View propositions.', 'Lists pending propositions the alliance is voting on.'), ...buildingIdRequestBody, responses: { ...response200('Lists pending propositions the alliance is voting on.', { type: 'object', required: ['propositions', 'status'], properties: { propositions: { type: 'array', items: { type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' }, description: { type: 'string' }, votes_needed: { type: 'integer' }, votes_yes: { type: 'integer' }, votes_no: { type: 'integer' }, status: { type: 'string' }, date_ends: { type: 'string' }, proposed_by: { type: 'object', properties: { id: { type: 'integer' }, name: { type: 'string' } }, }, my_vote: { type: 'integer', enum: [1, 0], description: 'Only present if this empire has voted.', }, }, }, }, status: statusSchema(), }, }), ...response500(), }, }, }, [`${base}/cast_vote`]: { post: { ...tags(base), ...security(), ...operation('Cast vote.', 'Casts a vote on a proposition. Throws 1018 if already voted.'), ...requestBodySchema({ type: 'object', required: ['building_id', 'proposition_id', 'vote'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, proposition_id: { type: 'integer', description: 'The id of the proposition being voted on. See view_propositions.', }, vote: { type: 'integer', enum: [1, 0], description: '1 for yes, 0 for no. Defaults to 0.', }, }, }), responses: { ...response200('Casts a vote on a proposition. Throws 1018 if already voted.', { type: 'object', required: ['status'], properties: { status: statusSchema() }, }), ...response500(), }, }, }, };