package Visual_DVM_2021.Passes.Server;
import Common.Current;
import Common.Database.DBObject;
import Common.Database.riDBObject;
import Repository.RepositoryServer;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
public class PublishServerObject<S extends RepositoryServer, D extends DBObject> extends ServerObjectPass<S, D> {
    public Object pk = null;
    public PublishServerObject(S server_in, Class<D> d_in) {
        super(server_in, d_in);
    }
    @Override
    public String getIconPath() {
        return "/icons/RedAdd.png";
    }
    //--
    @Override
    protected boolean canStart(Object... args) throws Exception {
        pk = null;
        if (Current.getAccount().CheckRegistered(Log)) {
            target = d.newInstance();
            if (target instanceof riDBObject) {
                riDBObject rTarget = (riDBObject) target;
                rTarget.sender_name = Current.getAccount().name;
                rTarget.sender_address = Current.getAccount().email;
            }
            return fillObjectFields();
        }
        return false;
    }
    protected String getEmail(){return null;}
    //--
    @Override
    protected void ServerAction() throws Exception {
        Command(new ServerExchangeUnit_2021(ServerCode.PublishObject, getEmail(), target));
        pk = response.object;
    }
    @Override
    protected void showDone() throws Exception {
        super.showDone();
        getDb().tables.get(d).ui_.Show(pk);
    }
}
