/*
 * SDK Pullenti Lingvo, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software.
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.ner.link;

/**
 * Связь сущностей
 */
public class LinkReferent extends com.pullenti.ner.Referent {

    public LinkReferent() {
        super(OBJ_TYPENAME);
        setInstanceOf(MetaLink.GLOBALMETA);
    }

    /**
     * Имя типа сущности TypeName ("LINK")
     */
    public static final String OBJ_TYPENAME = "LINK";

    /**
     * Имя атрибута - тип связи
     */
    public static final String ATTR_TYPE = "TYPE";

    /**
     * Имя атрибута - параметр связи (если есть)
     */
    public static final String ATTR_PARAM = "PARAM";

    /**
     * Имя атрибута - ссылка на первую сущность связи
     */
    public static final String ATTR_OBJECT1 = "OBJECT1";

    /**
     * Имя атрибута - ссылка на вторую сущность связи
     */
    public static final String ATTR_OBJECT2 = "OBJECT2";

    /**
     * Имя атрибута - дата начала
     */
    public static final String ATTR_DATEFROM = "DATEFROM";

    /**
     * Имя атрибута - дата окончания
     */
    public static final String ATTR_DATETO = "DATETO";

    public LinkType getTyp() {
        String str = this.getStringValue(ATTR_TYPE);
        if (str == null) 
            return LinkType.UNDEFINED;
        try {
            return (LinkType)LinkType.of(str);
        } catch (Exception ex2310) {
        }
        return LinkType.UNDEFINED;
    }

    public LinkType setTyp(LinkType value) {
        this.addSlot(ATTR_TYPE, value.toString().toLowerCase(), true, 0);
        return value;
    }


    public String getTypString() {
        String val = this.getStringValue(ATTR_TYPE);
        if (val == null) 
            return null;
        String res = (String)com.pullenti.unisharp.Utils.notnull(MetaLink.TYPES.convertInnerValueToOuterValue(val, null), val);
        return res.toLowerCase();
    }


    public String getParam() {
        return this.getStringValue(ATTR_PARAM);
    }

    public String setParam(String value) {
        this.addSlot(ATTR_PARAM, value, true, 0);
        return value;
    }


    @Override
    public com.pullenti.ner.Referent getParentReferent() {
        return getObject1();
    }


    public com.pullenti.ner.Referent getObject1() {
        return (com.pullenti.ner.Referent)com.pullenti.unisharp.Utils.cast(this.getSlotValue(ATTR_OBJECT1), com.pullenti.ner.Referent.class);
    }

    public com.pullenti.ner.Referent setObject1(com.pullenti.ner.Referent value) {
        this.addSlot(ATTR_OBJECT1, value, true, 0);
        return value;
    }


    public com.pullenti.ner.Referent getObject2() {
        return (com.pullenti.ner.Referent)com.pullenti.unisharp.Utils.cast(this.getSlotValue(ATTR_OBJECT2), com.pullenti.ner.Referent.class);
    }

    public com.pullenti.ner.Referent setObject2(com.pullenti.ner.Referent value) {
        this.addSlot(ATTR_OBJECT2, value, true, 0);
        return value;
    }


    public com.pullenti.ner.date.DateReferent getDateFrom() {
        return (com.pullenti.ner.date.DateReferent)com.pullenti.unisharp.Utils.cast(this.getSlotValue(ATTR_DATEFROM), com.pullenti.ner.date.DateReferent.class);
    }

    public com.pullenti.ner.date.DateReferent setDateFrom(com.pullenti.ner.date.DateReferent value) {
        this.addSlot(ATTR_DATEFROM, value, true, 0);
        return value;
    }


    public com.pullenti.ner.date.DateReferent getDateTo() {
        return (com.pullenti.ner.date.DateReferent)com.pullenti.unisharp.Utils.cast(this.getSlotValue(ATTR_DATETO), com.pullenti.ner.date.DateReferent.class);
    }

    public com.pullenti.ner.date.DateReferent setDateTo(com.pullenti.ner.date.DateReferent value) {
        this.addSlot(ATTR_DATETO, value, true, 0);
        return value;
    }


    @Override
    public String toStringEx(boolean shortVariant, com.pullenti.morph.MorphLang lang, int lev) {
        StringBuilder tmp = new StringBuilder();
        if (getTyp() != LinkType.UNDEFINED) 
            tmp.append(MetaLink.TYPES.convertInnerValueToOuterValue(this.getStringValue(ATTR_TYPE), null));
        if (getParam() != null) {
            if (tmp.length() > 0) 
                tmp.append(", ");
            tmp.append(this.getParam());
        }
        if (getDateFrom() != null && getDateTo() != null) {
            if (tmp.length() > 0) 
                tmp.append(", ");
            if (getDateFrom() == getDateTo()) 
                tmp.append(this.getDateFrom().toStringEx(true, null, 0));
            else 
                tmp.append("с ").append(this.getDateFrom().toStringEx(true, null, 0)).append(" по ").append(this.getDateTo().toStringEx(true, null, 0));
        }
        else if (getDateFrom() != null) {
            if (tmp.length() > 0) 
                tmp.append(", ");
            tmp.append("с ").append(this.getDateFrom().toStringEx(true, null, 0));
        }
        else if (getDateTo() != null) {
            if (tmp.length() > 0) 
                tmp.append(", ");
            tmp.append("по ").append(this.getDateTo().toStringEx(true, null, 0));
        }
        if (getObject2() != null && !shortVariant) {
            if (tmp.length() > 0) 
                tmp.append(", ");
            tmp.append(this.getObject2().toStringEx(true, null, 0));
        }
        return tmp.toString();
    }

    @Override
    public boolean canBeEquals(com.pullenti.ner.Referent obj, com.pullenti.ner.core.ReferentsEqualType _typ) {
        LinkReferent lr = (LinkReferent)com.pullenti.unisharp.Utils.cast(obj, LinkReferent.class);
        if (lr == null) 
            return false;
        if (lr.getObject1() != getObject1() || lr.getObject2() != getObject2()) 
            return false;
        return true;
    }

    public static LinkReferent _new2298(com.pullenti.ner.Referent _arg1, com.pullenti.ner.Referent _arg2) {
        LinkReferent res = new LinkReferent();
        res.setObject1(_arg1);
        res.setObject2(_arg2);
        return res;
    }

    public static LinkReferent _new2299(LinkType _arg1, com.pullenti.ner.Referent _arg2, com.pullenti.ner.Referent _arg3) {
        LinkReferent res = new LinkReferent();
        res.setTyp(_arg1);
        res.setObject1(_arg2);
        res.setObject2(_arg3);
        return res;
    }

    public static LinkReferent _new2300(LinkType _arg1, com.pullenti.ner.Referent _arg2) {
        LinkReferent res = new LinkReferent();
        res.setTyp(_arg1);
        res.setObject2(_arg2);
        return res;
    }

    public static LinkReferent _new2306(com.pullenti.ner.Referent _arg1, com.pullenti.ner.Referent _arg2, LinkType _arg3) {
        LinkReferent res = new LinkReferent();
        res.setObject1(_arg1);
        res.setObject2(_arg2);
        res.setTyp(_arg3);
        return res;
    }

    public static LinkReferent _new2307(com.pullenti.ner.Referent _arg1) {
        LinkReferent res = new LinkReferent();
        res.setObject1(_arg1);
        return res;
    }
}
