--
-- acs_sc_operation__new/7
--
create or replace function acs_sc_operation__new(
  character varying,
  character varying,
  text,
  boolean,
  integer,
  character varying,
  character varying
) returns int4 as $$

declare
    p_contract_name		alias for $1;
    p_operation_name            alias for $2;
    p_operation_desc		alias for $3;
    p_operation_iscachable_p	alias for $4;
    p_operation_nargs		alias for $5;
    p_operation_inputtype	alias for $6;
    p_operation_outputtype	alias for $7;
    v_contract_id               integer;
    v_operation_id		integer;
    v_operation_inputtype_id	integer;
    v_operation_outputtype_id	integer;
begin

    v_contract_id := acs_sc_contract__get_id(p_contract_name);

    v_operation_id := acs_object__new(
                         null,
                         'acs_sc_operation',
                         now(),
                         null,
                         null,
                         null
                     );

     v_operation_inputtype_id := acs_sc_msg_type__get_id(p_operation_inputtype);

     v_operation_outputtype_id := acs_sc_msg_type__get_id(p_operation_outputtype);

    insert into acs_sc_operations (
        contract_id,
        operation_id,
	contract_name,
	operation_name,
	operation_desc,
	operation_iscachable_p,
	operation_nargs,
	operation_inputtype_id,
	operation_outputtype_id
    ) values (
        v_contract_id,
        v_operation_id,
	p_contract_name,
	p_operation_name,
	p_operation_desc,
	p_operation_iscachable_p,
	p_operation_nargs,
	v_operation_inputtype_id,
	v_operation_outputtype_id
    );

    return v_operation_id;

end;$$ language plpgsql;