/** Common types for the consent components */
import { ConsentActionType, ConsentConfig, ConsentEvent } from '@signatu/consent';
import PropTypes from 'prop-types';


export interface ConsentProps {
    /** Access Token and API Key */
    config: ConsentConfig

    /** The subject principal */
    subject: string
    /** The issuer principal */
    issuer: string
    /** What is being consented to, e.g., a URL */
    target: string
    /** Where the consent request was placed, e.g., a URL */
    source?: string
    /** Scope of the consent */
    scope?: string
    /** The delegate principal, e.g., a customer service representative */
    delegate?: string
    /** Use opt-out - i.e., interpret no action as a go-ahead */
    optOut?: boolean

    /** Type of controls - BUTTONS or CHECKBOX */
    type?: ConsentActionType

    /** Consent request text or element */
    text?: string | JSX.Element
    /** Consent request title text or element */
    title?: string | JSX.Element
    /** Consent request subtitle text or element */
    subtitle?: string | JSX.Element

    /** ISO 639-1 language code */
    language?: string

    /** Callback when initial loading of Consent is complete */
    onLoaded?(consent?: ConsentEvent): void
    /** Callback when user has taken action */
    onAction?(consent: ConsentEvent): void
}

export const CONSENT_BASE_PROPTYPES = {
    /** Access Token and API Key */
    // config: PropTypes.object.isRequired,  
    config: PropTypes.object.isRequired as PropTypes.Validator<ConsentConfig>, 
    subject: PropTypes.string.isRequired, 
    /** The issuer principal */
    issuer: PropTypes.string.isRequired, 
    /** The target URL */
    target: PropTypes.string.isRequired, 
    /** The scope */
    scope: PropTypes.string as PropTypes.Validator<string | undefined>, 
    /** The source URL where the consent request was presented */
    source: PropTypes.string as PropTypes.Validator<string | undefined>, 
    /** The delegate principal, e.g., a customer service representative */
    delegate: PropTypes.string as PropTypes.Validator<string | undefined>, 

    optOut: PropTypes.bool as PropTypes.Validator<boolean | undefined>, 

    text: PropTypes.string as PropTypes.Validator<string | undefined>, 
    title: PropTypes.oneOfType([
        PropTypes.string, 
        PropTypes.element
    ]) as PropTypes.Validator<string | JSX.Element>, 
    subtitle: PropTypes.oneOfType([
        PropTypes.string, 
        PropTypes.element
    ]) as PropTypes.Validator<string | JSX.Element>, 

    language: PropTypes.string as PropTypes.Validator<string | undefined>,
    onLoaded: PropTypes.func  as PropTypes.Validator<(consent?: ConsentEvent | undefined) => any | undefined>,
    onAction: PropTypes.func as PropTypes.Validator<(consent?: ConsentEvent | undefined) => any | undefined>
}

