
/*---------------------------------------------------------------------------*/
/* ical.h                                                                    */
/* copyright (c) innovaphone 2025                                            */
/*---------------------------------------------------------------------------*/

enum class ical_component_t {
    UNKOWN,
    VCALENDAR,
    VEVENT,
    VTODO,
    VJOURNAL,
    VFREEBUSY,
    VTIMEZONE,
    STANDARD,
    DAYLIGHT,
    VALARM,
    VAVAILABILITY,
    AVAILABLE,
    PARTICIPANT,
    VLOCATION,
    VRESOURCE
};

enum class ical_property_t {
    UNKOWN,
    CALSCALE,
    METHOD,
    PRODID,
    VERSION,
    X_CALEND,
    X_CALSTART,
    X_CLIPEND,
    X_CLIPSTART,
    X_MICROSOFT_CALSCALE,
    X_MS_OLK_FORCEINSPECTOROPEN,
    X_MS_WKHRDAYS,
    X_MS_WKHREND,
    X_MS_WKHRSTART,
    X_OWNER,
    X_PRIMARY_CALENDAR,
    X_PUBLISHED_TTL,
    X_WR_CALDESC,
    X_WR_CALNAME,
    X_WR_RELCALID,
    ATTACH,
    CATEGORIES,
    CLASS,
    COMMENT,
    DESCRIPTION,
    GEO,
    LOCATION,
    PERCENT_COMPLETE,
    PRIORITY,
    RESOURCES,
    STATUS,
    SUMMARY,
    COMPLETED,
    DTEND,
    DUE,
    DTSTART,
    DURATION,
    FREEBUSY,
    TRANSP,
    TZID,
    TZNAME,
    TZOFFSETFROM,
    TZOFFSETTO,
    TZURL,
    ATTENDEE,
    CONTACT,
    ORGANIZER,
    RECURRENCE_ID,
    RELATED_TO,
    URL,
    UID,
    EXDATE,
    RDATE,
    RRULE,
    ACTION,
    REPEAT,
    TRIGGER,
    CREATED,
    DTSTAMP,
    LAST_MODIFIED,
    SEQUENCE,
    REQUEST_STATUS,
    X_ALT_DESC,
    X_MICROSOFT_CDO_ALLDAYEVENT,
    X_MICROSOFT_CDO_APPT_SEQUENCE,
    X_MICROSOFT_CDO_ATTENDEE_CRITICAL_CHANGE,
    X_MICROSOFT_CDO_BUSYSTATUS,
    X_MICROSOFT_CDO_IMPORTANCE,
    X_MICROSOFT_CDO_INSTTYPE,
    X_MICROSOFT_CDO_INTENDEDSTATUS,
    X_MICROSOFT_CDO_OWNERAPPTID,
    X_MICROSOFT_CDO_OWNER_CRITICAL_CHANGE,
    X_MICROSOFT_CDO_REPLYTIME,
    X_MICROSOFT_DISALLOW_COUNTER,
    X_MICROSOFT_EXDATE,
    X_MICROSOFT_ISDRAFT,
    X_MICROSOFT_MSNCALENDAR_ALLDAYEVENT,
    X_MICROSOFT_MSNCALENDAR_BUSYSTATUS,
    X_MICROSOFT_MSNCALENDAR_IMPORTANCE,
    X_MICROSOFT_MSNCALENDAR_INTENDEDSTATUS,
    X_MICROSOFT_RRULE,
    X_MS_OLK_ALLOWEXTERNCHECK,
    X_MS_OLK_APPTLASTSEQUENCE,
    X_MS_OLK_APPTSEQTIME,
    X_MS_OLK_AUTOFILLLOCATION,
    X_MS_OLK_AUTOSTARTCHECK,
    X_MS_OLK_COLLABORATEDOC,
    X_MS_OLK_CONFCHECK,
    X_MS_OLK_CONFTYPE,
    X_MS_OLK_DIRECTORY,
    X_MS_OLK_MWSURL,
    X_MS_OLK_NETSHOWURL,
    X_MS_OLK_ONLINEPASSWORD,
    X_MS_OLK_ORGALIAS,
    X_MS_OLK_SENDER,
    BUSYTYPE,
    NAME,
    REFRESH_INTERVAL,
    SOURCE,
    COLOR,
    IMAGE,
    CONFERENCE,
    CALENDAR_ADDRESS,
    LOCATION_TYPE,
    PARTICIPANT_TYPE,
    RESOURCE_TYPE,
    STRUCTURED_DATA,
    STYLED_DESCRIPTION,
    ACKNOWLEDGED,
    PROXIMITY,
    CONCEPT,
    LINK,
    REFID
};

enum class ical_parameter_t {
    UNKOWN,
    ALTREP,
    CN,
    CUTYPE,
    DELEGATED_FROM,
    DELEGATED_TO,
    DIR,
    ENCODING,
    FMTTYPE,
    FBTYPE,
    LANGUAGE,
    MEMBER,
    PARTSTAT,
    RANGE,
    RELATED,
    RELTYPE,
    ROLE,
    RSVP,
    SENT_BY,
    TZID,
    VALUE,
    X_FILENAME,
    X_MS_OLK_RESPTIME,
    X_MICROSOFT_ISLEAPMONTH,
    DISPLAY,
    EMAIL,
    FEATURE,
    LABEL,
    ORDER,
    SCHEMA,
    DERIVED,
    GAP,
    LINKREL 
};

enum class ical_version_t {
    VERSION_1_0,
    VERSION_2_0
};

extern const char * ICalComponentTypeToStr(ical_component_t component);
extern ical_component_t StrToICalComponentType(const char * componentName);

extern const char * ICalPropertyTypeToStr(ical_property_t property);
extern ical_property_t StrToICalPropertyType(const char * propertyName);

extern const char * ICalParameterTypeToStr(ical_parameter_t param);
extern ical_parameter_t StrToICalParameterType(const char * paramName);


class IICalParameter {
public:
    virtual ~IICalParameter() {}
    
    virtual ical_parameter_t Type() = 0;
    virtual const char * TypeStr() = 0;
    virtual const char * Name() = 0;
    virtual const char * Value() = 0;
    virtual void Value(const char * value) = 0;
};


class IICalProperty {
public:
    virtual ~IICalProperty() {}
    
    virtual ical_property_t Type() = 0;
    virtual const char * TypeStr() = 0;
    
    virtual const char * Name() = 0;
    virtual const char * Value() = 0;
    virtual void Value(const char * value) = 0;
    virtual size_t ParameterCount() = 0;
    virtual IICalParameter * Parameter(ical_parameter_t parameterType) = 0;
    virtual IICalParameter * Parameter(size_t index) = 0;
    virtual IICalParameter * Parameter(const char * name) = 0;
    virtual IICalParameter * NextParameter(const IICalParameter * fromParam) = 0;
    
    virtual IICalParameter * AddParameter(ical_parameter_t parameterType, const char * value) = 0;
    virtual IICalParameter * AddParameter(const char * parameterName, const char * value) = 0;
    virtual void RemoveParameter(IICalParameter * parameter) = 0;
    virtual void RemoveParameter(const char * name) = 0;
};


class IICalComponent {
public:
    virtual ~IICalComponent() {}
    
    virtual ical_component_t Type() = 0;
    virtual const char * TypeStr() = 0;
    
    virtual size_t ComponentCount() = 0;
    virtual size_t ComponentCount(ical_component_t type) = 0;
    virtual IICalComponent * Component(ical_component_t componentType) = 0;
    virtual IICalComponent * Component(size_t index) = 0;
    virtual IICalComponent * Component(const char * name) = 0;
    virtual IICalComponent * NextComponent(const IICalComponent * fromCompoment) = 0;
    virtual IICalComponent * NextComponent(const IICalComponent * fromCompoment, ical_component_t type) = 0;
    
    virtual size_t PropertyCount() = 0;
    virtual size_t PropertyCount(ical_property_t type) = 0;
    virtual IICalProperty * Property(ical_property_t propertyType) = 0;
    virtual IICalProperty * Property(size_t index) = 0;
    virtual IICalProperty * Property(const char * name) = 0;
    virtual IICalProperty * NextProperty(const IICalProperty * fromProperty) = 0;
    virtual IICalProperty * NextProperty(const IICalProperty * fromProperty, ical_property_t type) = 0;
    
    virtual IICalComponent * AddComponent(ical_component_t component) = 0;
    virtual void RemoveComponent(IICalComponent * component) = 0;
    virtual void RemoveComponent(ical_component_t type, bool removeFirstOnly = true) = 0;
    
    virtual IICalProperty * AddProperty(ical_property_t property, const char * value) = 0;
    virtual IICalProperty * AddProperty(const char * propertyName, const char * value) = 0;
    virtual void RemoveProperty(IICalProperty * property) = 0;
    virtual void RemoveProperty(ical_property_t type, bool removeFirstOnly = true) = 0;
    virtual void RemoveProperty(const char * name, bool removeFirstOnly = true) = 0;
};


class IICal {
public:
    static IICal * Create(class IInstanceLog * log = nullptr);
    
    virtual ~IICal() {}
    
    virtual bool Parse(const byte * data, size_t dataSize) = 0;
    virtual bool Parse(const char * data) = 0;
    
    virtual void Init(const char * iso9070_FPI, ical_version_t version = ical_version_t::VERSION_2_0) = 0;
    virtual void Init(const char * vendorID, const char * productID, const char * lng = "EN", bool isRegisteredVendor = false, ical_version_t version = ical_version_t::VERSION_2_0) = 0;
    virtual bool Encode() = 0;
    virtual const byte * Buffer() = 0;
    virtual size_t BufferSize() = 0;
    
    virtual IICalComponent * Root() = 0;
};
