import { operation, buildingBase, buildingCommonMethods, buildingView, requestBodySchema, response200, response500, security, speciesSchema, statusSchema, tags, } from '../../chunks.ts'; const base = buildingBase('GeneticsLab'); const buildingIdRequestBody = requestBodySchema({ type: 'object', required: ['building_id'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' } }, }); const experimentResultSchema = ( description: string, extraProperties: object = {}, extraRequired: string[] = [] ) => ({ ...response200(description, { type: 'object', required: [ 'status', 'grafts', 'survival_odds', 'graft_odds', 'essentia_cost', 'can_experiment', ...extraRequired, ], properties: { status: statusSchema(), grafts: { type: 'array', items: { type: 'object', properties: { spy: { type: 'object', description: 'The prisoner spy available to be experimented on.', properties: { id: { type: 'integer' }, name: { type: 'string' } }, required: ['id', 'name'], }, species: speciesSchema(), graftable_affinities: { type: 'array', items: { type: 'string' }, description: "Names of the species attributes this prisoner's traits can be grafted onto.", }, }, required: ['spy', 'species', 'graftable_affinities'], }, }, survival_odds: { type: 'integer', description: 'Percent chance the prisoner survives the experiment.', }, graft_odds: { type: 'integer', description: 'Percent chance the graft succeeds.' }, essentia_cost: { type: 'integer' }, can_experiment: { type: 'integer', enum: [1, 0] }, ...extraProperties, }, }), ...response500(), }); export const geneticsLab = { ...buildingCommonMethods(base), ...buildingView(base), [`${base}/prepare_experiment`]: { post: { ...tags(base), ...security(), ...operation( 'Prepare experiment.', 'Returns everything needed to set up a genetic graft experiment.' ), ...buildingIdRequestBody, responses: experimentResultSchema( 'Returns everything needed to set up a genetic graft experiment.' ), }, }, [`${base}/run_experiment`]: { post: { ...tags(base), ...security(), ...operation( 'Run experiment.', 'Experiments on a prisoner, attempting to graft one of their genetic traits onto the empire species. Returns the same shape as prepare_experiment plus an experiment result.' ), ...requestBodySchema({ type: 'object', required: ['building_id', 'spy_id', 'affinity'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, spy_id: { type: 'integer', description: 'The unique id of the spy.' }, affinity: { type: 'string', description: "One of the prisoner's graftable_affinities to attempt to graft onto the species.", }, }, }), responses: experimentResultSchema( 'Experiments on a prisoner, attempting to graft one of their genetic traits onto the empire species. Returns the same shape as prepare_experiment plus an experiment result.', { experiment: { type: 'object', properties: { graft: { type: 'integer', enum: [1, 0], description: 'Whether the graft succeeded.' }, survive: { type: 'integer', enum: [1, 0], description: 'Whether the prisoner survived.', }, message: { type: 'string' }, }, required: ['graft', 'survive', 'message'], }, }, ['experiment'] ), }, }, [`${base}/rename_species`]: { post: { ...tags(base), ...security(), ...operation( 'Rename species.', "Updates the empire's species name and description. Can throw error codes 1000 (name not available) and 1005 (contains invalid characters), with the offending field in the error's data." ), ...requestBodySchema({ type: 'object', required: ['building_id', 'params'], properties: { building_id: { type: 'integer', description: 'The unique id of the building.' }, params: { type: 'object', description: 'The species name and description to set.', required: ['name'], properties: { name: { type: 'string', description: "The empire's new species name. Limited to 30 characters, cannot be blank, and cannot contain @, &, <, >, or ;.", }, description: { type: 'string', description: "The species' description. Limited to 1024 characters, cannot contain < or >.", }, }, }, }, }), responses: { ...response200( "Updates the empire's species name and description. Can throw error codes 1000 (name not available) and 1005 (contains invalid characters), with the offending field in the error's data.", { type: 'object', required: ['success'], properties: { success: { type: 'string' } } } ), ...response500(), }, }, }, };