export class AsanaSync {
    client;
    mapper;
    constructor(client, mapper) {
        this.client = client;
        this.mapper = mapper;
    }
    buildTaskName(ticket) {
        return `${ticket.id}: ${ticket.title}`;
    }
    buildTaskNotes(ticket) {
        const parts = [ticket.description?.trim() || '', '', '---', `Synced from PMO ticket ${ticket.id}`];
        return parts.join('\n').trim();
    }
    isCompletedStatus(ticket) {
        return ticket.statusCategory === 'completed' || ticket.statusCategory === 'canceled';
    }
    async createTaskForTicket(ticket, projectGid) {
        const task = await this.client.createTask({
            name: this.buildTaskName(ticket),
            notes: this.buildTaskNotes(ticket),
            completed: this.isCompletedStatus(ticket),
            projects: [projectGid],
        });
        this.mapper.createOrUpdateMapping(ticket.id, task.gid, projectGid);
        return task.gid;
    }
    async syncTicket(ticket, taskGid) {
        await this.client.updateTask(taskGid, {
            name: this.buildTaskName(ticket),
            notes: this.buildTaskNotes(ticket),
            completed: this.isCompletedStatus(ticket),
        });
        this.mapper.updateSyncTimestamp(ticket.id);
    }
}
//# sourceMappingURL=sync.js.map