package parlament

// Session is a plenary session (Nationalrat or Bundesrat).
type Session struct {
	Date   string
	Title  string
	Agenda string
	GPCode string
	// Path is the portal-relative URL for this session, usable with Client.GetDetail.
	Path string
}

type SessionFilter struct {
	// Chamber is "NR" (Nationalrat) or "BR" (Bundesrat).
	Chamber []string
	// Period is the legislative period in Roman numerals, e.g. "XXVIII".
	Period []string
}

// ListSessions returns plenary sessions matching the given filter.
// Leave a field nil/empty to omit that dimension.
func (c *Client) ListSessions(f SessionFilter) ([]Session, int, error) {
	payload := map[string]any{}
	if len(f.Chamber) > 0 {
		payload["NRBRBV"] = f.Chamber
	}
	if len(f.Period) > 0 {
		payload["GP"] = f.Period
	}

	resp, err := c.postFilter("WFP_007", payload)
	if err != nil {
		return nil, 0, err
	}

	idx := colIndex(resp.Header)
	sessions := make([]Session, 0, len(resp.Rows))
	for _, row := range resp.Rows {
		sessions = append(sessions, Session{
			Date:   strCol(row, idx, "Datum"),
			Title:  strCol(row, idx, "Sitzung"),
			Agenda: strCol(row, idx, "Tagesordnung"),
			GPCode: strCol(row, idx, "gp_code"),
			Path:   strCol(row, idx, "pfad"),
		})
	}
	return sessions, resp.Count, nil
}
