export class TrelloSync {
    client;
    mapper;
    constructor(client, mapper) {
        this.client = client;
        this.mapper = mapper;
    }
    buildCardName(ticket) {
        return `${ticket.id}: ${ticket.title}`;
    }
    buildCardDesc(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 createCardForTicket(ticket, listId, boardId) {
        const card = await this.client.createCard({
            name: this.buildCardName(ticket),
            desc: this.buildCardDesc(ticket),
            closed: this.isCompletedStatus(ticket),
            idList: listId,
            ...(boardId ? { idBoard: boardId } : {}),
        });
        this.mapper.createOrUpdateMapping(ticket.id, card.id, boardId);
        return card.id;
    }
    async syncTicket(ticket, cardId) {
        await this.client.updateCard(cardId, {
            name: this.buildCardName(ticket),
            desc: this.buildCardDesc(ticket),
            closed: this.isCompletedStatus(ticket),
        });
        this.mapper.updateSyncTimestamp(ticket.id);
    }
}
//# sourceMappingURL=sync.js.map